> [!NOTE] Definition (Diffie–Hellman key exchange algorithm) >**Output**: Shared secret key. > >**Procedure:** > > 1. **Public parameter creation**: A trusted party chooses and publishes a large [[Prime numbers|prime]] $p,$ and some [[Primitive Root Modulo n|primitive root]] of $\mathbb{Z}/p\mathbb{Z},$ call it $g.$ >1. **Private computations**: Alice and Bob choose a secret integers $a$ and $b$ respectively and compute $A\equiv g^{a} \pmod{p}$ and $B\equiv g^{b} \pmod{p}.$ >1. **Public exchange of values**: Alice sends $A$ to Bob and Bob sends $B$ to Alice. >1. **Further private computations**: Alice computes $B^{a} \pmod{p}$ and Bob computes $A^{b} \pmod{p}$ which both equal $g^{ab} \pmod{p}.$ The DHKE is based on the intractability of [[Diffie-Hellman Problem|DHP]]. > [!Example] > Alice and Bob choose $p=37$ and primitive root 5, these are both public. Alice now chooses $a=8$, and Bob chooses some b. Alice computes $5^8=390625 \equiv 16$ $(\bmod 37)$. Bob computes $5^b \equiv 14(\bmod 37)$. Alice now computes$ 5^{a b}=14^8=1475789056 \equiv 26 \quad(\bmod 37) .$ >The key is thus $26$, then use favourite method to use this key to encrypt a message.