๐Ÿ”‘ Diffie-Hellman Key Exchange Demo

This is an educational demo. Small numbers are not suitable for real security.

Aliceโ€™s public key (A = g^a mod p)8
Bobโ€™s public key (B = g^b mod p)19
Shared secret (Aliceโ€™s side: B^a mod p)2
Shared secret (Bobโ€™s side: A^b mod p)2
โœ“ Both sides computed the same shared secret

Enter a prime p, a generator g, and both partiesโ€™ private keys (a, b) to see how the Diffie-Hellman key exchange algorithm computes public keys and a shared secret. Confirm for yourself that both sides independently arrive at the same shared secret via different calculation paths.

How to use

  1. Enter the prime p and generator g.
  2. Enter Aliceโ€™s and Bobโ€™s private keys (a, b).
  3. The public keys (A, B) and the matching shared secret computed by each side are shown automatically.

FAQ

What is Diffie-Hellman key exchange?

An algorithm that lets two parties with no prior shared secret establish a common secret key over an insecure channel. It underlies many encrypted protocols, including TLS.

Why do both sides get the same shared secret?

Because of the laws of exponents: (g^a)^b mod p and (g^b)^a mod p are always mathematically equal.

Can I use these small numbers for real security?

No โ€” this is an educational demo to illustrate the mechanism. Real-world use requires very large primes (2048 bits or more).