🔐 Diffie-Hellman Key Exchange

Discover how two parties can securely establish a shared secret key over an insecure channel without ever directly exchanging the key itself.

Interactive Demonstration

👤

Alice

Private Key: ?

Public Key: ?

⟷
👤

Bob

Private Key: ?

Public Key: ?

Prime (p)
23
Generator (g)
5
Alice's Secret (a)
?
Bob's Secret (b)
?
Shared Secret
?

Step 1: Public Parameters

Alice and Bob agree on public parameters: a prime number p and a generator g.

p = 23, g = 5

Step 2: Private Key Generation

Each party generates a private key (random number).

Alice chooses secret 'a', Bob chooses secret 'b'

Step 3: Public Key Calculation

Each party calculates their public key using the formula:

Public Key = g^(private key) mod p

Step 4: Public Key Exchange

Alice and Bob exchange their public keys over the insecure channel.

Alice sends A = g^a mod p, Bob sends B = g^b mod p

Step 5: Shared Secret Computation

Each party computes the shared secret using the received public key:

Shared Secret = (received public key)^(own private key) mod p

🛡️ Security Note

The security of Diffie-Hellman relies on the discrete logarithm problem - it's computationally infeasible to determine the private keys from the public keys and parameters. Even if an eavesdropper intercepts the public keys, they cannot compute the shared secret without solving the discrete logarithm problem.