Labs / Computer Science
Diffie-Hellman Exchange
Alice and Bob each keep a private key secret, yet they can agree on the same shared number by sending only public values across an open wire. Set their private keys, pick a prime and generator, and step through the exchange — then look at what the eavesdropper is stuck with.
stage secretA 8B 19Alice s …Bob s …match …
What to try
- Alice sends A and Bob sends B, yet both end at the same s. How can two different public numbers lead to one identical secret?
- Change only Alice's private key. Which numbers on the wire change, and does Bob still land on the matching secret?
- Eve captures p, g, A, and B — every value that crossed the wire. Why can't she just reverse the math to recover the private keys?
- Switch to a larger prime like p = 197. How much harder does the “g to the x” guessing game get for Eve?
- What happens to the shared secret if you set a private key to 1? Is that a good key to choose, and why not?