b2KIT

Diffie-Hellman Key Exchange Visualizer

Interactive visualization of classical Diffie-Hellman key exchange with color-mixing analogy and modular arithmetic steps.

Tested tool guide Tested browser tools Checked August 16, 2026

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

Follow one complete exchange from public parameters through both matching secret calculations. Enter a prime modulus p, a base g, and separate private exponents for Alice and Bob. The visualizer shows each public value, then uses the received public value to derive the same result on both sides, alongside a color-mixing analogy. The common surprise is that Alice's and Bob's public values are meant to be exposed, while their private exponents and the resulting shared secret must remain confidential. Matching outputs demonstrate agreement, not authentication or production-grade security.

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 = 5^6 mod 23 = 8. Bob public value B = 5^15 mod 23 = 19. Alice computes 19^6 mod 23 = 2, and Bob computes 8^15 mod 23 = 2. The shared secret is 2.

Each side combines the other side's public value with its own private exponent. Both calculations reduce to 5^(6*15) mod 23, so they produce the same residue, 2.

How the result is produced

1

Create public values

With modulus p and base g, Alice selects private exponent a and publishes A = g^a mod p. Bob selects b and publishes B = g^b mod p. The color track distinguishes the common starting value, each private contribution, and the values sent across the public channel. It is an analogy for the exchange, not another cryptographic calculation.

2

Derive the shared secret

After exchanging A and B, Alice computes s = B^a mod p while Bob computes s = A^b mod p. Both equal g^(ab) mod p, so the displayed secrets match. The arithmetic steps help check modular powers, whose final residues can be small even when ordinary exponentiation would produce very large numbers.

Good uses

  • Checking a classroom exercise that asks for public values and the shared residue from small p, g, a, and b values.
  • Showing why two participants can publish different modular powers yet still calculate an identical shared value.
  • Changing one private exponent to observe how its public value and the resulting shared secret change.

Limits and checks

  • Small integers make the steps readable but also make private exponents easy to recover by trial, so the example says nothing about real-world strength.
  • The color-mixing analogy illustrates contribution and combination; paint behavior does not define modular arithmetic or quantify resistance to reversal.
  • Equal shared-secret values confirm the arithmetic only. Plain Diffie-Hellman does not identify the other participant and permits an active man-in-the-middle attack without authentication.

Common questions

Why can both sides get the same number without sending their private exponents?

Alice raises Bob's public value to a, producing (g^b)^a, while Bob raises Alice's public value to b, producing (g^a)^b. Exponent multiplication gives the same g^(ab) before reduction modulo p. The public values carry the needed mathematical contribution without directly transmitting a or b.

Can I use the displayed shared secret directly as an encryption key?

No. A small integer from this visualizer is an educational result, not a deployable key. A secure protocol must also address parameter selection, private-value generation, public-value validation, peer authentication, and key derivation. The visualizer verifies the core equality but does not turn hand-entered demonstration values into a secure communications protocol.

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