Alice's walk (g^a mod p) Bob's walk (g^b mod p) Shared secret K
⚠ Couldn't load the 3D engineThree.js failed to load from the CDN. Check your connection and reload.

Diffie-Hellman Key Exchange: Modular Exponentiation Walk

This simulator visualizes the Diffie-Hellman key exchange — the modular-arithmetic handshake that lets two parties agree on a shared secret over a public channel — as a 3D walk around a ring of residues modulo a prime p. Each step multiplies the current value by the generator g and reduces mod p, spiralling upward one exponent at a time; Alice's and Bob's independent walks, driven by their private exponents a and b, land on completely different-looking public values A and B, yet raising each other's public value to one's own private exponent always converges on the identical shared secret K = g^(ab) mod p. Live readouts track both public values, the shared secret from each side, and the current exponent step, while a collapsible section spells out the actual governing formula and why the discrete logarithm problem — inverting the walk to recover a private exponent from a public value — has no known efficient classical solution, which is exactly what keeps this exchange secure in real-world TLS connections.