Diffie-Hellman Key Exchange

Two people (Alice & Bob) agree on a shared secret over a public channel — without ever transmitting the secret itself. Even an eavesdropper (Eve) who sees everything cannot recover it.

This demo shows both the math (modular exponentiation) and the paint analogy (mixing colors is easy; un-mixing is hard).

Public values — visible to everyone, including Eve
Alice's private secret — known only to Alice
Bob's private secret — known only to Bob
Shared secret — derived independently, identical result
Eve — can intercept messages but cannot compute the secret

Click Next Step to advance manually, or Auto Play to animate. You can change secret values in the parameter cards below.

Diffie-Hellman Key Exchange
Cryptographic key agreement over an insecure channel
Step 1 of 6 — Agree on public parameters
Speed
Prime p (public)
23
Generator g (public)
5
Alice's secret a
Bob's secret b
Alice sends A = g^a mod p
Bob sends B = g^b mod p
Shared Secret
Step Log