Exemple #1
0
from DiffieHellman import DiffieHellman

dhAlice = DiffieHellman()
g, p, publicKey = dhAlice.getBaseAndModulusAndPublicKey()
dhBob = DiffieHellman(g, p, publicKey)

print(dhBob.sharedSecret == dhAlice.calcSecret(dhBob.publicKey))
Exemple #2
0
        # Look for the response
        amount_received = 0
        amount_expected = len(message)

        while amount_received < amount_expected:
            data = sock.recv(4096)
            amount_received += len(data)
            # print('received: %s' % data.decode('utf-8'))
            # header, body = data.decode('utf-8').split('|')
            data = pickle.loads(data)
            header = data['header']
            body = data['data']

            if header == "DH":
                bobPublicKey = int(body)
                aliceSharedSecret = dhAlice.calcSecret(bobPublicKey)
                print('Alice SharedSecret(%d): %d' %
                      (aliceSharedSecret.bit_length(), aliceSharedSecret))

                aesOBJ = AESCipher(str(aliceSharedSecret))
                enc = aesOBJ.encrypt('this is test AES cipher message')
                toSend['header'] = 'AES'
                toSend['data'] = enc
            elif header == "AES":
                decryptedBody = aesOBJ.decrypt(body)
                print("RESPONSE: %s" % decryptedBody)
                inpt = input('Your message > ')
                enc = aesOBJ.encrypt(inpt)

                toSend['header'] = 'AES'
                toSend['data'] = enc