Diffie-Hellman Key Exchange Visualizer
Watch two sides land on the same shared secret without ever transmitting it, with small real numbers.
Diffie–Hellman answers a question that sounds impossible: how do two people agree on a shared secret while everyone is listening? Step through it with small numbers and the trick becomes clear — both sides do the same operations in a different order and land on the same value, while an eavesdropper who saw everything sent cannot.
How to use it
- Set the shared prime p and generator g — these are public.
- Choose Alice's private secret a and Bob's private secret b.
- Follow what each sends, then what each computes, and confirm both arrive at the same shared secret.
What to take away
Only the private secrets stay hidden
p, g, and both transmitted values are public. Security rests on the discrete logarithm problem: recovering a from g^a mod p is infeasible at real key sizes.
Real parameters are enormous
The numbers here are small so the arithmetic is visible. Production uses 2048-bit or larger groups, or elliptic curves, where the same idea holds with far shorter keys.
It has no authentication of its own
Plain Diffie–Hellman is wide open to a machine in the middle running two exchanges at once. That is why TLS pairs it with certificates — the exchange gives secrecy, the certificate gives identity.
Frequently asked questions
Why can an eavesdropper not compute the shared secret?
They see g, p, g^a mod p and g^b mod p, but computing g^ab mod p from those requires solving the discrete logarithm, which has no known efficient classical algorithm at real key sizes.
What is forward secrecy?
Using a fresh ephemeral Diffie–Hellman exchange per session, so that compromising the server's long-term key later does not decrypt traffic captured earlier. It is why modern TLS prefers ECDHE.
Does quantum computing break this?
Shor's algorithm would break both Diffie–Hellman and RSA on a sufficiently large quantum computer, which is why post-quantum key exchange is being standardised and deployed now.
Where this fits in the course
This security tool pairs with Path 06 — Cryptography — see all 26 learning paths.
It runs entirely in your browser: nothing is uploaded, no account is needed, and it is free.
Related
- Cipher Playground — Caesar/ROT, XOR, and Vigenère — the classic ciphers from the CTF zone.
- Entropy Calculator — Shannon entropy of any text — a genuine static-analysis signal for spotting packed or encrypted data.
- Timing Attack Visualizer — See exactly why a naive string comparison leaks how many leading characters were correct — and why constant-time comparison fixes it.
- Hash Generator — SHA-1, SHA-256, SHA-384, SHA-512 of any text, via the browser's crypto engine.