mod = 53
base = 5
index_a = 30
index_b = 25
class Diffie_Hellman_Key_Exchanger(object):
def __init__(self, base=None, mod=None, _private_index=None, external_message=None):
self.base = base
self.mod = mod
self._private_index = _private_index
self.external_message = None
self.public_message = None
self._key = None
def get_public_message(self):
self.public_message = self.base ** self._private_index % self.mod
return self.public_message
def get_key(self):
self._key = self.external_message ** self._private_index % self.mod
return self._key
Alice = Diffie_Hellman_Key_Exchanger(base, mod, index_a)
Bob = Diffie_Hellman_Key_Exchanger(None, None, index_b)
Alice.get_public_message()
Bob.base, Bob.mod, Bob.external_message = Alice.base, Alice.mod, Alice.public_message
Bob.get_public_message()
Alice.external_message = Bob.public_message
print(Alice.get_key(), Bob.get_key())