BigInt Precision
All modular exponentiation uses JavaScript BigInt, enabling accurate computation with large primes including the 2048-bit MODP group from RFC 3526 — same as real TLS implementations.
Simulate the complete Diffie-Hellman key exchange protocol with BigInt precision — custom prime, generator, private keys, step-by-step computation and shared secret verification.
Enter parameters, set private keys and compute the shared secret step by step.
For real applications use 2048-bit+ primes (MODP groups from RFC 3526) or switch to ECDH with Curve25519. Select the MODP-2048 preset above. Never use small primes in production — they are trivially brute-forced.
Everything you need to understand and test Diffie-Hellman key exchange.
All modular exponentiation uses JavaScript BigInt, enabling accurate computation with large primes including the 2048-bit MODP group from RFC 3526 — same as real TLS implementations.
Every computation is broken into 7 labelled steps showing exact formulas and numeric results — perfect for learning, teaching or verifying manual calculations.
Real-time validation checks that p is a prime, g is a valid generator, private keys are in the valid range, and warns when parameters are too small for production security.
Includes the production-safe MODP-2048 group (Group 14) from RFC 3526, the same prime used in OpenSSH, OpenVPN, TLS/SSL and IPsec implementations worldwide.
Automatically verifies that Alice and Bob independently arrive at the identical shared secret — proving the mathematical correctness of the Diffie-Hellman theorem.
Export the complete DH exchange — parameters, public keys, private keys and shared secret — as a structured JSON object for use in documentation, testing or research.
Four mathematical steps to establish a shared secret over a public channel.
Both parties publicly agree on a large prime p and a primitive root g. These values are known to everyone including eavesdroppers.
Alice picks secret a, computes A = ga mod p. Bob picks secret b, computes B = gb mod p. Each sends their public value to the other.
Alice computes S = Ba mod p. Bob computes S = Ab mod p. The discrete log problem ensures these are equal even though neither knows the other's private key.
The shared secret S is hashed (e.g. SHA-256) to derive a symmetric session key for use in AES or ChaCha20 encryption of the actual communication channel.
The Diffie-Hellman key exchange — published by Whitfield Diffie and Martin Hellman in 1976 — was the first publicly known protocol that solved one of cryptography's hardest problems: how can two parties securely agree on a shared secret when their entire conversation is visible to an adversary? The answer lies in the mathematical hardness of the discrete logarithm problem: computing gx mod p is easy, but reversing it to find x from gx mod p is computationally infeasible for large primes.
The Diffie-Hellman algorithm forms the backbone of modern internet security. It is embedded in every HTTPS connection (as ECDHE in TLS 1.3), every SSH session, OpenVPN tunnels, IPsec VPNs and Signal Protocol end-to-end encryption. The "E" in ECDHE stands for "ephemeral" — a new DH key pair is generated per session, ensuring perfect forward secrecy: compromise of long-term keys does not expose past session data.
A Diffie-Hellman calculator such as this one lets you explore the protocol hands-on — see exactly which values are public, which are secret, and why an eavesdropper who intercepts A and B cannot recover the shared secret without solving the discrete log. For educational purposes, small primes like p=23 make the numbers tractable; in production, 2048-bit safe primes (RFC 3526 MODP groups) or elliptic curves (Curve25519) provide security against even nation-state-level adversaries.
Key use cases include: TLS/HTTPS key exchange, SSH host authentication, encrypted messaging apps, VPN tunnel establishment, blockchain node communication, and IoT device provisioning. Best practices: always use ephemeral keys (DHE/ECDHE) for forward secrecy, authenticate public keys via certificates or pre-shared tokens to prevent MITM attacks, and prefer ECDH with Curve25519 over classic DH for performance and security in new implementations.
Common questions about Diffie-Hellman key exchange, security and applications.
Discover our complete suite of cryptography, AI and developer tools — all free, no sign-up required.
🍪 We use cookies to improve your experience. By using this site, you agree to our Cookie Policy.