# Proof of the Diffie-Hellman Key Exchange

Could someone please provide the math proof;

$$((g^a)\bmod p)^b \bmod p = ((g^b)\bmod p)^a \bmod p$$

Let $$g^a = x \bmod p$$ and $$k \in \mathbb{Z}$$ the we can write $$g^a$$ with the help of the remainder theorem; $$g^a = x + k \cdot p$$ Now take $$b$$-th power of both sides under modulus $$p$$.

\begin{align} (g^a)^b &= (x + k \cdot p)^b &\pmod p\\ g^{ab} &= \binom{b}{0} x^b + \binom{b}{1}x^{b-1}(k \cdot p) + \cdots + \binom{b}{b}x^0(k \cdot p)^b &\pmod p\\ g^{ab} &= x^b &\pmod p \end{align}

Similarly;

Let $$g^b = y \bmod p$$ then $$g^b = y + \ell \cdot p$$ now take $$a$$-th power and as above

\begin{align} (g^b)^a &= (y + \ell \cdot p)^a &\pmod p\\ g^{ab} &= \binom{a}{0} y^a + \binom{a}{1}y^{a-1}(\ell \cdot p) + \cdots + \binom{a}{a}y^0(\ell \cdot p)^a &\pmod p\\ g^{ab} &= y^a &\pmod p \end{align}

Now we have $$x^b = g^{ab} = y^a \pmod p$$ Therefore both side has the same values.

• The binomial coefficient is missing. Mar 5, 2022 at 12:30
• @DINEDINE Thanks again, I've corrected it. Mar 5, 2022 at 17:39