Modular Arithmetic and Primality
Modular Arithmetic and Primality Modular Arithmetic and Primality
Given an integer p, we want to state if it is prime or not (i.e. it is only divisible by 1 and itself) Could check all factors, but... All known approaches to factoring take exponential time How about trying to divide by all numbers less then p/2 We have Fermat’s little theorem Some examples If p is prime, then a p-1 ≡ 1 mod p for any a such that 1 ≤ a < p CS 312 - Complexity Examples - Arithmetic and RSA 28
function primality(N) Input: Positive integer N Output: yes/no // a is random positive integer between 2 and N-1 a = uniform(2 … N-1) if (modexp(a, N-1, N) == 1): return yes else: return no Is this correct CS 312 - Complexity Examples - Arithmetic and RSA 29
- Page 1 and 2: Addition Multiplication Bigger Ex
- Page 3 and 4: Addition of two numbers of length n
- Page 5 and 6: Addition of two numbers of length n
- Page 7 and 8: Isn’t addition in a computer just
- Page 9 and 10: x y 15 11 At each step double x and
- Page 11 and 12: ⎧⎧ 2(x⋅ ⎣⎣y/2⎦⎦) if y
- Page 13 and 14: x y y binary # of x’s 15 8 0 1 30
- Page 15 and 16: function multiply(x,y) Input: Two n
- Page 17 and 18: Is multiplication O(n 2 ) - Could w
- Page 19 and 20: Assume we start with numbers Mod N
- Page 21 and 22: There is a faster algorithm - Rathe
- Page 23 and 24: ⎧⎧ (x ⎣⎣y/2⎦⎦ ) 2 if y
- Page 25 and 26: x y y binary power of x z return va
- Page 27: function modexp (x, y, N) //Iterati
- Page 31 and 32: How often does a composite number c
- Page 33 and 34: Primality testing is efficient! - O
Given an integer p, we want to state if it is prime or not<br />
(i.e. it is only divisible by 1 <strong>and</strong> itself)<br />
Could check all factors, but...<br />
All known approaches to factoring take exponential time<br />
How about trying to divide by all numbers less then p/2<br />
We have Fermat’s little theorem<br />
Some examples<br />
If p is prime, then a p-1 ≡ 1 mod p<br />
for any a such that 1 ≤ a < p<br />
CS 312 - Complexity Examples - <strong>Arithmetic</strong> <strong>and</strong> RSA 28