Modular Arithmetic (cont.)
Like normal arithmetic: commutative, associative and distributive
Can reduce intermediate results modulo n.
(a*b) mod n = ((a mod n)(b mod n) mod n)
Speeding up exponentiation in modular arithmetic
a8 mod n = (a*a*a*a*a*a*a*a) mod n
= ((a2 mod n) 2 mod n) 2 mod n
a 25 mod n = (a*a 8 * a 16) mod n
= (a* ((a2) 2 ) 2 * (((a 2) 2) 2) 2 ) mod n
= (a* (((a * a 2) 2) 2) 2) mod n
Can be done in O( log x) operations [a x mod n]