b2KIT

Diffie-Hellman Key Exchange Visualizer

Simulate the Diffie-Hellman protocol with color-mixing analogy. Shows how shared secrets emerge from public exchanges.

Tested tool guide Tested browser tools Checked August 16, 2026

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

Follow a finite-field Diffie-Hellman exchange from private exponents to matching shared values, with a color-mixing analogy distinguishing private material, public material, and the combined result. Enter a public modulus and base plus one private value for each participant. The visualizer shows the public values they exchange and the secret each side derives. The common surprise is that the exchanged values are not themselves the shared secret. The colors are only an analogy: the actual calculation is modular exponentiation, not literal color blending.

Worked example

A concrete input and expected output from the current implementation.

Input

p = 23; g = 5; Alice private = 6; Bob private = 15

Expected output

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

Alice publishes 5^6 mod 23 = 8, while Bob publishes 5^15 mod 23 = 19. Alice then computes 19^6 mod 23 = 2, and Bob computes 8^15 mod 23 = 2, so both sides reach the same value.

How the result is produced

1

Public value generation

Both participants use the same public modulus p and base g. Alice chooses private exponent a and produces A = g^a mod p. Bob independently chooses private exponent b and produces B = g^b mod p. Only A and B need to cross the public channel; a and b remain private.

2

Shared secret agreement

After exchanging public values, Alice calculates B^a mod p and Bob calculates A^b mod p. These expressions are equal because each reduces to g^(ab) mod p. The visualizer represents that convergence as matching final colors, connecting the analogy to the numerical exchange.

Good uses

  • Checking each modular-exponentiation step in a small classroom Diffie-Hellman exercise.
  • Demonstrating why two parties can derive the same value without transmitting that value directly.
  • Comparing how different private exponents change the public values while preserving agreement between the two final calculations.

Limits and checks

  • Small example parameters are useful for inspection but are not secure cryptographic parameters.
  • A matching result confirms the arithmetic exchange, not the identity of either participant or the security of the communication channel.
  • The displayed shared integer is protocol material, not necessarily a ready-to-use encryption key; practical systems usually derive keys from the agreement result.

Common questions

Does Diffie-Hellman authenticate Alice and Bob?

No. Basic Diffie-Hellman establishes a common secret but does not prove who supplied either public value. An attacker who can replace messages may establish separate secrets with both participants. Real protocols therefore combine key agreement with authentication, such as signatures, certificates, or previously shared credentials.

Can someone recover the private values from this small example?

Yes. With p = 23, an observer can simply test possible exponents until the public values match. The example illustrates the arithmetic only. Security depends on approved parameter groups large enough to make the relevant discrete-logarithm problem impractical, along with correct protocol use.

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