Toolgeist › Developer

Diffie-Hellman Key Exchange Visualizer — Real Modular Exponentiation

Real modular exponentiation via BigInt (not floating point, which loses precision almost immediately at these exponents) — Alice and Bob each independently compute the identical shared secret using only publicly exchanged values, having never transmitted the secret itself. The default numbers are the textbook example (p=23, g=5, a=6, b=15). A live eavesdropper panel brute-forces the discrete log for small primes to make concrete exactly why real Diffie-Hellman needs a prime hundreds of digits long instead.

How to use Diffie-Hellman Key Exchange Visualizer

  1. Set a prime p, generator g, and private keys a and b.
  2. Watch Alice and Bob's public values and shared secret compute.
  3. Confirm both sides land on the identical shared secret.
  4. Try the eavesdropper panel on a small prime to see the private keys recovered live.

Frequently asked questions

Why does g^(ab) mod p come out the same both ways?
Alice computes (g^b)^a mod p and Bob computes (g^a)^b mod p — both reduce to g^(ab) mod p with the multiplication order swapped, which modular exponentiation does not care about, so neither party ever needed the other's private exponent to arrive at the same value.
What can an eavesdropper actually see?
Only the prime p, generator g, and both public values A and B — never the private exponents a or b, and never the shared secret itself, which is the entire point of the exchange.
Why can the demo brute-force small primes but real DH is considered secure?
Recovering a private exponent from a public value requires solving the discrete logarithm problem — brute-forceable in milliseconds for a tiny prime like 23, but computationally infeasible for a real 2048-bit-or-larger prime, which is exactly why real implementations use primes hundreds of digits long.
Is this the same algorithm used in real HTTPS connections?
Yes — Diffie-Hellman (commonly its elliptic-curve variant, ECDHE) is how TLS establishes a shared session key for HTTPS, letting your browser and a server agree on a secret over a connection that might be observed.

Related Developer tools

Also searched for: diffie hellman key exchange demo · modular exponentiation calculator · discrete log brute force visualizer

Browse all 738 free tools on Toolgeist →