Diffie-Hellman Key Exchange Simulator
Watch two parties agree on a shared secret over a public channel.
About this tool
Diffie-Hellman (1976) was the breakthrough that made public-key cryptography possible: two people who have never met can agree on a shared secret while an eavesdropper watches every message. This simulator lets you set the public prime and generator, choose Alice's and Bob's private exponents, and see each public value and the resulting shared secret computed with exact BigInt arithmetic.
The math is g^a mod p and g^b mod p exchanged in the open; each side raises the other's public value to its own private exponent, both landing on g^(ab) mod p. Small demo parameters are used so the numbers are readable — real deployments use 2048-bit or larger primes, or elliptic-curve variants.
Like everything on encrypt.tools, this runs entirely in your browser — nothing you enter is transmitted or stored.
Frequently asked questions about Diffie-Hellman Simulator
How can two people share a secret if an attacker sees everything?+
The security rests on the discrete logarithm problem: knowing g, p, and g^a mod p, it is computationally infeasible to recover the private exponent a for large primes. Alice and Bob each combine their own secret with the other's public value to reach the same result an eavesdropper cannot compute.
Why are the numbers in this tool so small?+
Small parameters keep the shared secret readable so you can follow the math. Real Diffie-Hellman uses primes of 2048 bits or more (or elliptic curves), where the numbers are hundreds of digits long.
Is Diffie-Hellman still used today?+
Yes — every HTTPS connection uses an ephemeral Diffie-Hellman exchange (usually the elliptic-curve variant, ECDHE) to establish forward-secret session keys. The principle you see here underlies TLS, SSH, and Signal.
Related tools
RSA Key Generator
Generate RSA key pairs and export them as PEM
RSA-OAEP · SHA-256RSA Encrypt / Decrypt
Encrypt with a public key, decrypt with a private key
ECDSA · P-256/384/521ECC Key Generator
Generate P-256, P-384, and P-521 key pairs as PEM
ED25519 · X25519Ed25519 / X25519 Keys
Modern Curve25519 signing and key-exchange keys