Diffie-Hellman Key Exchange Protocol

  1. Alice and Bob agree on a large prime number n and another number g; these numbers may not be secret;
  2. Alice generates a random number x and sends to Bob the value: X = g^x mod n;
  3. Bob generates a random number y and sends to Alice the value: Y = g^y mod n;
  4. Alice receives the value of Y and computes: K_x = Y^x mod n;
  5. Bob receives the value of X and computes K_y = X^y mod n;

The algorithm ensures that the values K_x and K_y are equal and can be used as a key in a secret-key encryption algorithm.