Example #1
0
 def testing(self):
     test = list(range(0, len(self.sifted_key)))
     self.test_indices = sample(test, len(self.sifted_key) // 2)
     print("test indices :", self.test_indices)
     for i in self.test_indices:
         self.test_key.append(self.sifted_key[i])
     print("Alice key for testing :", self.test_key)
     msg1 = comm.list_to_bytes(self.test_key)
     self.cqc_sender.sendClassical(self.receiver, msg1)
     time.sleep(1)
     msg2 = comm.list_to_bytes(self.test_indices)
     self.cqc_sender.sendClassical(self.receiver, msg2)
Example #2
0
 def sifting(self):
     x = self.cqc_sender.recvClassical()
     B_basis = x.decode()
     k = sifted_key(self.basis, B_basis, self.initial_k)
     for i in k[0]:
         self.sifted_key.append(int(i))
     self.sifted_basis = k[1]
     print("Alice sifted key", self.sifted_key)
     msg = comm.list_to_bytes(self.sifted_basis)
     self.cqc_sender.sendClassical(self.receiver, msg)
Example #3
0
    def privacy_amplification(self):
        self.private_key = ''

        randBinList = lambda n: [randint(0, 1) for b in range(1, n + 1)]
        kl = len(self.sifted_key)  #len of sifted key
        L = randBinList(kl)
        sifted_key = []

        msg = comm.list_to_bytes(L)
        self.cqc_sender.sendClassical(self.receiver, msg)

        for i in range(len(L)):
            self.private_key += str(np.dot(self.sifted_key[i], L[i]) % 2)

        print("Alice private key :", self.private_key)
Example #4
0
    print("Alice sifted key", aa[0])

    listToStr = "[" + ','.join(map(str, aa[1])) + "]"
    ff = listToStr.encode()
    Alice.sendClassical("Bob", ff)

    #####################TEST N RANDOM BITS################################
    test_key = []
    test = list(range(0, len(aa[0])))

    test_indices = sample(test, len(aa[0]) // 2)
    print(test_indices)
    for i in test_indices:
        test_key.append(aa[0][i])
    print("Test KEY", test_key)
    msg1 = comm.list_to_bytes(test_key)
    Alice.sendClassical('Bob', msg1)
    time.sleep(1)
    test2 = ''

    msg2 = comm.list_to_bytes(test_indices)
    Alice.sendClassical('Bob', msg2)

    #################### OTHER RECONCILIATION##########################

    #Later Alice will xor two from list indices, send indices and xor result to Bob
    """
 x=0
 f or i,j in enumerate(test_indices):
	x=(sifted_key[j]+sifted_key[j+1])%2
	print("positions",j)