Diffie-Hellman Key Exchange Demonstrator
Watch Alice and Bob independently arrive at the same shared secret, without ever sending it directly.
About this tool
Alice and Bob each pick a private key and never share it. They exchange only their public values (A and B), computed as g^private mod p. Each then raises the OTHER person's public value to their OWN private key — both arrive at g^(a×b) mod p, without either ever transmitting a or b. Real Diffie-Hellman uses primes hundreds of digits long; these small numbers are for illustrating the maths, not real security.
You can type numbers of any size: the calculations use exact whole-number arithmetic, so a 30-digit prime works as well as 23. The tool checks that p really is prime and that g and the private keys are in range, and the line under the result shows what an eavesdropper would see. Try a large prime such as 170141183460469231731687303715884105727 (2127 − 1) to see why recovering a private key from the public values becomes impractical. Modern systems mostly use the elliptic-curve version (ECDH), which works the same way with smaller keys.