Maths WorkshopMaths problems with full solutions
Exercise 1581Number theory › CongruencesL1Added 3 Nov 2026

The Diffie–Hellman protocol

#Diffie-Hellman#cryptography#modular

Statement

Describe the Diffie–Hellman key exchange and explain its security relies on the discrete logarithm problem.

Hint

Alice and Bob each choose a secret exponent and exchange gag^a and gbg^b.

Show solutionHide solution

Solution

Setup. Public prime pp and primitive root gg mod pp.

Protocol.
1. Alice picks secret aa, sends A=ga mod pA=g^a\bmod p to Bob.
2. Bob picks secret bb, sends B=gb mod pB=g^b\bmod p to Alice.
3. Alice computes Ba=gabB^a=g^{ab}; Bob computes Ab=gabA^b=g^{ab}. Shared key: gab mod pg^{ab}\bmod p.

Security. An eavesdropper sees p,g,A,Bp,g,A,B and must compute gabg^{ab} from these, which requires solving the discrete logarithm problem (finding aa from gag^a), believed to be hard.

Conclusion. Diffie–Hellman relies on modular arithmetic and the hardness of discrete logarithm.