S
S
Stefan752019-06-20 17:23:52
Python
Stefan75, 2019-06-20 17:23:52

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)

Result:
Alice Key: 5283143412
Bob Key: 5283143412
Eva Key 5283143412

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2019-06-20
@Rsa97

Because in real systems much larger numbers are used. For p , for example, a 2048-bit prime is recommended. As you understand, g a and g b must be significantly larger than p , otherwise the meaning of the module is lost.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question