Skip to content
Infinitesimal Dynamics home
Notebook: 0 XP

Cryptography / Public-key cryptography

Diffie–Hellman Key Exchange

Two strangers agree on a shared secret over a channel everyone can hear.

3 min read · 2 sections · 1 checks

Contents 3 sections
  1. §1The protocol
  2. §2Why eavesdroppers are stuck
  3. ?Check yourself

By the end you can

  • Run the Diffie–Hellman protocol with small numbers
  • Explain the discrete logarithm problem
  • Recognise the man-in-the-middle risk

Helps to know: Substitution and Shift Ciphers

§1The protocol

Alice and Bob publicly agree on a prime pp and a base gg. Alice picks a secret aa and sends A=ga mod pA = g^a \bmod p. Bob picks a secret bb and sends B=gb mod pB = g^b \bmod p. Each can now compute the same number:

Ba≡(gb)a=gab=(ga)b≡Ab(modp)B^a \equiv (g^b)^a = g^{ab} = (g^a)^b \equiv A^b \pmod p

Example 1Small numbers

  1. p=23p = 23, g=5g = 5. Alice picks a=6a = 6: A=56 mod 23=8A = 5^6 \bmod 23 = 8.

§2Why eavesdroppers are stuck

An eavesdropper sees pp, gg, AA and BB. Recovering aa from ga mod pg^a \bmod p is the discrete logarithm problem, for which no efficient algorithm is known when pp has hundreds of digits.

Check yourself

  1. Q1
    Which value is never sent over the network in Diffie–Hellman?