Diffie-Hellman key exchange

This is just a small example of the algorithm itself. In real-life situations, you should use the multiplicative group of integers modulo p, where p is prime, and g is a primitive root modulo p to ensure maximum security. This example only shows the logic of how two actors in a key exchange can know the same secret key without transferring it publicly. Try changing the common or secret value of the actors to see how all the numbers change. The input fields are color-coded to show which numbers are the same, step by step.
For more information visit the Wikipedia page.

Coloring:

Actor A
Actor B

Common value

+
+

Secret value

=
=

New Public value

➡️
🔀 Exchanged values
⬅️

Exchanged public value

+
+

Secret value

=
=

The finished secret key
What happens in this example step by step:
  1. Both actors agree on a common value. This is public information.
  2. Each actor has a secret value. This value should never be revealed and should never leave its owner.
  3. Both actors add their own secret value to the common value. The result is a new public value.
  4. The actors exchange the new public values.
  5. Both actors add their own secret value to the exchanged public value. This results in a secret key known only by them, calculated and stored from different values.