%3C/text%3E%3C/svg%3E">
💻
💻 Tech & IT

Diffie-Hellman Key Exchange Calculator (educational)

Results update as you type.

Your numbers

Understanding the Diffie-Hellman key exchange calculator — concept and principle

Diffie-Hellman (DH) lets two parties who have never met agree on a shared secret over a channel that anyone can read. The shared secret is then turned into keys for encryption. This calculator uses small numbers so you can check each step by hand. Variants of the same idea run in every HTTPS connection today, usually on elliptic curves.

Diffie-Hellman with p = 23 and g = 5Alice sends 8 and Bob sends 19; each raises the other number to their own secret and both get 2.Same secret, never sent over the wirepublic: p = 23, g = 5Alicesecret a = 6Bobsecret b = 15A = 5⁶ mod 23 = 8B = 5¹⁵ mod 23 = 19(anyone may see 8 and 19)Alice: 19⁶ mod 23= 2Bob: 8¹⁵ mod 23= 2Shared secret = 2both get 5^(6×15) mod 23
Only 8 and 19 travel in public, yet Alice and Bob both arrive at the shared secret 2.

How it is calculated

Alice and Bob publicly agree on a prime p and a generator g. Then:

  1. Alice picks a secret a and sends A = gᵃ mod p.
  2. Bob picks a secret b and sends B = gᵇ mod p.
  3. Alice computes Bᵃ mod p; Bob computes Aᵇ mod p.

Both results equal g^(ab) mod p, which is the shared secret. The tool computes the powers with exact modular exponentiation and checks that both sides match.

The principle

Exponents multiply: (gᵇ)ᵃ = g^(ba) = (gᵃ)ᵇ, and this stays true when every step is reduced modulo p. An eavesdropper sees p, g, A and B but not a or b. Recovering a from A = gᵃ mod p is the discrete logarithm problem, and computing g^(ab) from gᵃ and gᵇ alone is believed to be just as hard for well-chosen large groups. In this toy group of 23 elements anyone can try all exponents; in a 2,048-bit group that is impossible in practice.

Worked example

  1. Inputs: p = 23, g = 5, Alice's a = 6, Bob's b = 15.
  2. A = 5⁶ mod 23 = 15,625 mod 23 = 8.
  3. B = 5¹⁵ mod 23 = 19.
  4. Alice: 19⁶ mod 23 = 2. Bob: 8¹⁵ mod 23 = 2.
  5. Shared secret = 2, and the check reads match.
How Shared secret changes with Alice secret aHow Shared secret changes with Alice sec…2468101.534.567.5912Example: 2Alice secret a
Each point is the calculator re-run with only “Alice secret a” changed; the gold point is the default example. Change the inputs above and this chart follows your numbers.
Alice secret aShared secret
1.52
35
4.55
62
7.52
910
124

How to read the result

"match" confirms that both sides derived the same value, as the algebra guarantees for whole-number inputs. A good g should generate a large subgroup; with a poor g the possible secrets collapse to a few values. In real systems the shared value is never used directly but passed through a key derivation function such as HKDF.

Common mistakes

Keep in mind: These tiny numbers are for learning only. Real deployments use standard groups of 2,048 bits or more, or curves such as X25519, implemented by a trusted library.

Frequently asked questions

Who invented Diffie-Hellman?

Whitfield Diffie and Martin Hellman published it in 1976; Ralph Merkle contributed the underlying idea of public key agreement.

What is ECDH or X25519?

The same exchange done on an elliptic curve group. It gives comparable security with much smaller keys, so it is faster.

Does Diffie-Hellman encrypt messages?

No. It only agrees on a secret; a symmetric cipher such as AES then encrypts the data.

Sources: W. Diffie, M. E. Hellman, "New Directions in Cryptography", IEEE Transactions on Information Theory 22(6), 1976 · IETF RFC 7748, Elliptic Curves for Security

Checked 8 Nov 2026. Standard formulas and RFC/IEEE definitions, computed locally in your browser — nothing you type is sent anywhere.

💻 All tech & IT tools →🌍 Calculators by country →