Answer the question
In order to leave comments, you need to log in
Diffie-Hellman protocol why does Eve pick up the key from me (Python3)?
Hey! I decided to deal with the Diffie-Hellman Protocol and added it to Python along the way.
But here's the snag, why can I, as a spy for Eve, pick up the key, for example, Alice?
g = 3
p = 7334832323
a = 15
b = 30
# функция для получения AB
def crypt_dh(g,p,ab):
result = g**ab % p
return result
A = crypt_dh(g,p,a)
B = crypt_dh(g,p,b)
# секретные ключиАлисы и Боба
k_Alice = B**a % p
k_Bob = A**b % p
print('Alice Key: ', k_Alice)
print('Bob Key: ', k_Bob)
# Ева знает g,p,A,B
def encrypt(g,p,AB,k_Name):
encryption = 'Fail'
for key in range(1000):
result = AB**key % p
if result == k_Name:
encryption = A**key % p
return encryption
# Результат шпиона
k_Eva = encrypt(g,p,A,k_Alice)
print('Eva Key: ', k_Eva)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question