Skip to content
D DocNectar

Free Diffie-Hellman Key Exchange Simulator

Educational simulator of the Diffie-Hellman key exchange using small, human-checkable numbers.

100% Free No Signup Works on all devices

Last updated October 10, 2026 · Report an error

Thanks for rating!

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.

  1. Enter prime modulus (p).
  2. Enter generator (g).
  3. Enter alice's private key (a).
  4. Enter bob's private key (b).
  5. 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.

Frequently asked questions

Yes, with no signup and no limit on how many exchanges you simulate.
No — this is strictly an educational demonstration using small numbers so every step is human-checkable. Real Diffie-Hellman requires primes hundreds of digits long; small numbers like these would be trivially breakable in real use.
The eavesdropper sees p, g, and both public values (A and B) — but computing the shared secret from those alone requires solving the discrete logarithm problem to recover a private key, which is computationally infeasible for real (large) primes, even though it's easy to brute-force for this simulator's small demo numbers.
GMP isn't available in this environment, so bcmath's bcpowmod() is used for arbitrary-precision modular exponentiation instead — mathematically exact either way, just a different underlying library.

Get new calculators and guides in your inbox

No spam — just new tools like Diffie-Hellman Key Exchange Simulator and practical guides.

Favorites