Diffie–Hellman key exchange
Diffie-hellman key Exchange (D-H) is a security protocol. It allows both parties to set up a key over an insecure channel without any prior information from the other party. This key can be used as a symmetric key in subsequent communications to encrypt the communication content.
- Alice and Bob publicly agree to use a modulus p = 23 and base g = 5 (which is a primitive root modulo 23).
- Alice chooses a secret integer a = 4, then sends Bob A = ga mod p
- A = 54 mod 23 = 4
- Bob chooses a secret integer b = 3, then sends Alice B = gb mod p
- B = 53 mod 23 = 10
- Alice computes s = Ba mod p
- s = 104 mod 23 = 18
- Bob computes s = Ab mod p
- s = 43 mod 23 = 18
- Alice and Bob now share a secret (the number 18).
Reference: https://en.wikipedia.org/wiki/Diffie%E2%80%93Hellman_key_exchange