Last updated October 10, 2026 · Report an error
Diffie-Hellman lets two parties agree on a shared secret over a public channel without ever transmitting the secret itself — the foundation of most modern secure key exchange. This simulator uses small, human-checkable numbers to make every step (the modular exponentiations) easy to verify by hand.
How it works
Enter a public prime modulus and generator, plus each side's private key. The tool computes each side's public value (g^private mod p), then the shared secret both sides arrive at independently (the other side's public value raised to your own private key, mod p) — and confirms both sides land on the same number.
- Enter prime modulus (p).
- Enter generator (g).
- Enter alice's private key (a).
- Enter bob's private key (b).
- Click Calculate to see your results.
Examples
The classic textbook example
With p=23, g=5, Alice's private key a=6, and Bob's private key b=15: Alice's public value is 8, Bob's is 19, and both independently compute a shared secret of 2 — without either ever transmitting their private key.
Who should use it
- Teaching or learning how Diffie-Hellman key exchange works step by step.
- Verifying an understanding of modular exponentiation with a concrete worked example.
Industry applications
- Cryptography and computer science education
- Security training and onboarding materials
Advantages
- Every intermediate value (public keys, shared secret) is shown, not just the final result.
- Small numbers make the underlying modular arithmetic genuinely checkable by hand.
Limitations
- Not usable for real cryptography — purely an educational demonstration with intentionally small, insecure numbers.
Common mistakes to avoid
- Assuming small demo-friendly numbers reflect real-world security — actual Diffie-Hellman needs primes far too large to check by hand.
- Entering a private key equal to or larger than the prime modulus, which falls outside the valid range for modular arithmetic here.
Best practices
- Work through one full example by hand (computing g^a mod p yourself) to build real intuition for why the shared secret matches on both sides.
- Use a real cryptographic library (not small hand-checkable numbers) for any actual key exchange in production code.
Tips
- Try changing just one private key and re-running — notice both public values change, but the mechanism for arriving at a shared secret stays the same.