Modular Arithmetic and Primality
Modular Arithmetic and Primality
Modular Arithmetic and Primality
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
⎧⎧ (x ⎣⎣y/2⎦⎦<br />
) 2 if y is even<br />
x y = ⎨⎨<br />
⎩⎩ x⋅ (x ⎣⎣y/2⎦⎦<br />
) 2 if y is odd<br />
function modexp (x, y, N)<br />
Input: € Two n-bit integers x <strong>and</strong> N, an integer exponent y (arbitrarily<br />
large)<br />
Output: x y mod N<br />
if y = 0: return 1<br />
z = modexp(x, floor(y/2), N)<br />
if y is even: return z 2 mod N<br />
else: return x · z 2 mod N<br />
CS 312 - Complexity Examples - <strong>Arithmetic</strong> <strong>and</strong> RSA 23