Diffie-Hellman Key Establishment

Follow these steps to run the Diffie-Hellman Key Establishment simulation.

Step 1: Public Information Setup

  • Set public parameters in either way:
    • Use Generate Prime to load a preset prime pp and default generator gg.
    • Or type your own values for pp and gg directly in the input boxes.
  • Optional: Click Another Generator to cycle valid preset generators for the currently selected preset prime.
  • Public parameters must satisfy p>2p > 2 and 1<g<p1 < g < p.

Step 2: Private Key Selection

  • For Alice:
    • Enter a private key aa manually, or click Generate A.
  • For Bob:
    • Enter a private key bb manually, or click Generate B.
  • Each private key must satisfy 0<a<p0 < a < p and 0<b<p0 < b < p.

Step 3: Public Key Calculation

  • For Alice, click Calculate g^a to compute:
    • A=gamodpA = g^a \bmod p
  • For Bob, click Calculate g^b to compute:
    • B=gbmodpB = g^b \bmod p

Step 4: Exchange Public Keys

  • Click Send Public Key to Bob to copy Alice's public key into Bob's received field.
  • Click Send Public Key to Alice to copy Bob's public key into Alice's received field.

Step 5: Shared Secret Computation

  • Alice clicks Calculate Shared Secret to compute:
    • KA=BamodpK_A = B^a \bmod p
  • Bob clicks Calculate Shared Secret to compute:
    • KB=AbmodpK_B = A^b \bmod p

Step 6: Verification

  • Check the verification status shown in Step 3.
  • Success condition:
    • KA=KBK_A = K_B
  • If the values do not match, verify that:
    • Both users used the same pp and gg.
    • Public keys were recalculated after any input change.
    • Public keys were exchanged before shared-secret calculation.

Notes on Simulation Behavior

  • The simulation clears stale computed outputs whenever core inputs change.
  • Validation messages are shown when inputs are out of range or missing.
  • This simulation demonstrates correctness of key establishment, not authentication against active attackers.