b2KIT

Diffie-Hellman Key Exchange Demo

Interactive demonstration of the Diffie-Hellman key exchange protocol with step-by-step visualization.

Tested tool guide Tested browser tools Checked August 16, 2026

What Diffie-Hellman Key Exchange Demo does, with a checked example

Diffie-Hellman Key Exchange Demo follows Alice and Bob as they combine a public prime modulus and base with separate private exponents. It displays each public value and the modular-exponentiation steps that give both sides the same shared result. The central surprise is that the shared secret is never sent between them. They exchange public values and independently calculate an equal number. The displayed result is educational arithmetic, not a ready-to-use encryption key or proof of the other party's identity.

Worked example

A concrete input and expected output from the current implementation.

Input

p = 23; g = 5; Alice private exponent a = 6; Bob private exponent b = 15

Expected output

Alice public value A = 8; Bob public value B = 19; Alice shared secret = 2; Bob shared secret = 2

The public values are 5^6 mod 23 = 8 and 5^15 mod 23 = 19. Alice then gets 19^6 mod 23 = 2, while Bob gets 8^15 mod 23 = 2.

How the result is produced

1

Public value calculation

With modulus p, base g, and private exponents a and b, the demonstration forms Alice's public value A = g^a mod p and Bob's public value B = g^b mod p. The model exposes p, g, A, and B for exchange while keeping a and b on their respective sides.

2

Shared secret calculation

Alice raises B to exponent a modulo p, and Bob raises A to exponent b modulo p. Both results equal g^(ab) mod p. The matching values are the shared secret shown at the final step. The demonstration establishes equality between the calculations; it does not reveal either private exponent from that equality.

Good uses

  • Checking the arithmetic in a classroom exercise involving a prime modulus, base, and two private exponents.
  • Showing how Alice and Bob reach an identical secret without transmitting that secret directly.
  • Observing how changing one private exponent affects its public value and the resulting shared secret.

Limits and checks

  • Small demonstration parameters can be searched by brute force and must not be treated as secure cryptographic parameters.
  • Basic Diffie-Hellman does not authenticate either participant, so matching calculations alone do not prevent a man-in-the-middle attack.
  • The displayed shared number is not automatically a suitable encryption key; deployed protocols normally perform additional validation and key derivation.

Common questions

Can someone recover a private exponent from the displayed public values?

With the deliberately small values suitable for a visual demo, often yes: someone can try exponents until a public value matches. That does not contradict Diffie-Hellman. Practical security depends on carefully selected groups and much larger private values. This demonstration explains the relationship; it does not certify any numbers as safe for deployment.

Why do Alice and Bob obtain the same shared secret?

Alice computes B^a mod p = (g^b)^a mod p, while Bob computes A^b mod p = (g^a)^b mod p. Both expressions reduce to g^(ab) mod p. A mismatch means the two sides did not use the same public parameters or the intended corresponding private and public values.

References and verification

The example and behavioral notes were checked against the browser implementation. Standards and primary references below define the relevant format, formula, or platform behavior.

Related Tools