The Variables

To start a handshake, we need two public numbers that everyone knows:

  • Base ():

  • Modulus ():

Step 1: The Private Secrets

Two parties, Alice and Shiva, choose secret numbers (Private Keys). These are never shared with anyone.

  • Alice chooses:

  • Shiva chooses:

Step 2: The Public Exchange

Both parties perform a calculation: and send the result to each other.

  • Alice calculates:

    • with a remainder of .

    • Alice sends to Shiva.

  • Shiva calculates:

    • with a remainder of .

    • Shiva sends to Alice.

Step 3: Creating the Shared Secret

Now, they take the number they received and raise it to their own private secret.

  • Alice receives and calculates:

    • Result =
  • Shiva receives and calculates:

    • Result =

The Shared Secret is . Both parties arrived at the exact same number without ever telling each other their secrets ( and ).


Why is this Secure?

An eavesdropper (or the server) sees the following numbers:

  • Base:

  • Mod:

  • Alice’s Result:

  • Shiva’s Result:

To steal the secret, the eavesdropper has to solve for in the equation: .

The “Trapdoor” Logic

  1. With small numbers (): You can easily “loop” through and find that , which satisfies the equation.

  2. With real-world numbers: In protocols like OMEMO, the modulus is not ; it is a number with 77 digits.

Even if a computer can do trillions of calculations per second, the “random” jumping of the numbers caused by the Modulo operation means there is no shortcut. The computer has to guess every single possibility, which would take longer than the age of the universe.


Conclusion

Diffie-Hellman is the reason you can trust your data on an open network. By using massive prime numbers, we turn a simple math problem into an unbreakable digital vault.