With respect to the maths behind the Diffie Hellman Key exchange algorithm.
Why does:
(ga mod p)b mod p = gab mod p
It might be fairly obvious, but what basic maths guarantees this? Why does the first modulo p expression disappear from the LHS in the expression on the RHS.
Apologies if it's not the right forum to ask it in. Maybe I should try the Stack Exchange Mathematics forum instead.
First, observe that for any a real, b real:
$((a \mod p) + b) \mod p = (a + b) \mod p$
Multiplication is just repeated addition. Therefore, you see for any a real,b integer:
$((a \mod p) \cdot b) mod p = (a \cdot b) \mod p$
Because:
$(\underbrace{(a \mod p) + ... + (a \mod p)}_{\text{b many times}}) \mod p = (\underbrace{a + ... + a }_{\text{b many times}}) \mod p$
With the same trick you show this for exponentiation, for all a real and b integer:
$((a \mod p) ^b) \mod p = (a ^b) \mod p$
Note that this trick only works for b being an integer, but that is given for DHE's case.
Now it should be obvious.