Lesson 7 of 15
Diffie-Hellman Key Exchange
Diffie-Hellman Key Exchange
Published by Whitfield Diffie and Martin Hellman in 1976, the Diffie-Hellman key exchange was the first practical public-key protocol. It allows two parties to establish a shared secret over an insecure channel without ever sending the secret itself.
The Protocol
Both parties agree on public parameters: a prime and a generator (a primitive root modulo ).
- Alice picks a private key , computes public key
- Bob picks a private key , computes public key
- Alice and Bob exchange and publicly
- Alice computes
- Bob computes
Both arrive at the same shared secret .
Why It's Secure
An eavesdropper sees , , , and , but cannot compute without solving the Discrete Logarithm Problem — finding from . This is believed to be computationally hard for large .
Classic Example
, (a prime), , :
| Party | Private | Public |
|---|---|---|
| Alice | ||
| Bob |
Shared secret: .
Your Task
Implement:
dh_public_key(g, private_key, p)— computedh_shared_secret(other_public, private_key, p)— compute
Python runtime loading...
Loading...
Click "Run" to execute your code.