Click on the steps of a Diffie-Hellman key exchange to see the values of the variables as they are chosen and computed. In the dashed boxes the information known to Alice and Box and the information that can be observed by the eavesdropper Eve is shown.
New Example Restart Example
Eve knows:
Alice knows Alice and Bob agree to use p, g Bob knows
Alice picks secret a Bob picks secret b

Alice computes

A=ga mod p

Bob computes

B=gb mod p
Alice sends A to Bob Bob sends B to Alice
Alice receives B from Bob Bob receives A from Alice

Alice computes

s=Ba mod p

Bob computes

s=Ab mod p
Now Alice and Bob share the secret s