-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbb84.py
41 lines (30 loc) · 1.43 KB
/
bb84.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from quantum.qkd import QKD
import argparse
def main(bits: int, toggle_eve: bool):
alice = QKD(bits)
bob = QKD(bits)
if toggle_eve:
eve = QKD(bits)
eve.recv(alice.send())
bob.recv(eve.send())
else:
bob.recv(alice.send())
print("Alice's basis: ", "".join(map(str, alice.basis)))
print("Bob's basis: ", "".join(map(str, bob.basis)))
print("Match? ", "".join(["x" if alice == bob else " " for alice, bob in zip(alice.basis, bob.basis)]))
print("Alice's sent bits:", "".join(map(str, alice.bits)))
print("Bob received bits:", "".join(map(str, bob.bits)))
print()
alice.prune(bob.basis)
bob.prune(alice.basis)
print("Alice pruned bits:", "".join(map(str, alice.bits)))
print("Match? ", "".join(["x" if alice == bob else " " for alice, bob in zip(alice.bits, bob.bits)]))
print("Bob's pruned bits:", "".join(map(str, bob.bits)))
if not alice.check_bits(bob.bits):
print("Eavesdropper detected!")
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="A simulator of the BB84 QKD protocol written using Python and Numpy.")
parser.add_argument("-b", "--bits", type=int, help="The number of bits to use", default=16)
parser.add_argument("-e", "--toggle-eve", action="store_true", help="Drop a eavesdropper between Alice & Bob")
args = parser.parse_args()
main(args.bits, args.toggle_eve)