Fast Modular Exponentiation

In Diffie-Hillman key exchange, as in many modern encryption schemes, a very important operation is modular exponentiation: xn mod m. Note that while xn can be quite a large number, far too large to be computed by most computers, xn mod m is a value between 0 and m−1 inclusive.