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$ then  $k \in \mathbb{Z}$; $$g^a = x + k \cdot p$$ Now take $b$-th power of both sides and $\bmod p$.
\begin{align}
(g^a)^b &amp;= (x + k \cdot p)^b \pmod p\\
g^{ab} &amp;= x^b + x^{b-1}(k \cdot p) + \cdots + (k \cdot p)^b \pmod p\\
g^{ab} &amp;= 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 $\bmod p$ and arrive
$$g^{ab} = y^a \pmod p$$
Therefore $$x^b = y^a = g^{ab} \pmod p$$