Primality Test Rog-Jaye Che
OUTLINE [1] Modular Arithmetic Algorithms [2] Quadratic Residues [3] Primality Testig p2.
[1] Modular Arithmetic Algorithms 1. The itegers a divides b a b a{ 1, b} If b has a divisor, the a is said to be otrivial. a is prime if it has o otrivial divisors; otherwise, a is composite. The prime theorem: { a is prime a [2, x]} ( x) ~ x / log x If c a ad c b, the c is commo divisor of a ad b. If d is a great commo divisor of a ad b, the we write d=gcd(a,b). p3.
Euclidea algorithm(a,b) (for great commo divisor) iput: a b 0 output: d gcd( a, b) (1) Set r 0 =a ad r 1 =b (2) Determie the first 0 so that r +1 =0, where r i+1 =r i-1 mod r i (3) Retur (r ) Exteded Euclidea algorithm(a,b) iput:a>0, b>0 output: (r, s, t) with r=gcd(a,b) ad sa+tb=r (Omitted) p4.
Example :gcd(299,221)=? 299 1 221 78 ( q 1, r2 2 221 2 78 65 ( q 2, r3 3 78) 65) 78 1 65 13 ( q 1, r4 4 13) 65 5 13 0 ( q 5, r5 5 0) gcd( 299,221) r4 13 78 65 78 (221 2 78) 3 78 221 3 (299 1 221) 221 3 299 4 221 p5.
If gcd(a,b)=1, the a ad b are said to be relatively prime. Phi fuctio: ( ) #{ a gcd( a, ) 1 ad 1 a } 1. ( p e ) 2. ( ab) ( p 1) p e1 for prime p ( a) ( b) for gcd( a, b) 1 p6.
2. The itegers modulo a is cogruet to b modulo, writte, if a-b. Z ={0,1,,-1} a b (mod ) Give a, if x Z s.t. ax 1 (mod ), the a is Z said to be ivertible ad its iverse x is deoted a -1. p7.
Use Exteded Euclidea Algo to calculate a -1 mod Example:a=7 ad =9 Euclidea algorithm to fid gcd(a,) 9 1 7 2 7 3 2 1 2 2 1 0 Exteded Euclidea algorithm to write gcd(a,b)=sa+t 1 7 3 2 7 3(9 1 7) 4 7 3 9 7 1 4 mod 9 p8.
Z *={a gcd(a,)=1 ad 0<a<} * ( ) is defied as Z For example, Z 12 *={1,5,7,11}, Z 15 *={1,2,4,7,8,11,13,14} (Z *, *) forms a multiplicatio group p9.
Fermat s little theorem: If a Z * p Euler s theorem: If a Z * * The order of, writte ord(a), as the least positive iteger t such that * Z ( p is prime), the a, the a Z ( ) * If a, has ord( a) Z ( ), the a is said to be a geerator of Z *; i this case, a p1 1 (mod ) a t 1(mod ). Z * 1 (mod p) { a i 0 i ( )}. p10.
Example :=15 Z 15 *={1,2,4,7,8,11,13,14} ψ(15)= ψ(3) ψ(5)=2*4=8 * a Z 15 1 2 4 7 8 11 13 14 ord (a) 1 4 2 4 2 2 4 2 p11.
3. Chiese remaider theorem If the itegers 1,, k are pairwise relatively prime, the the system of cogrueces x x a 1 (mod 1 ) a 2 (mod 2 ) x a k (mod k ) has a uique solutio modulo = 1 * 2 * * k p12.
Algorithm:Gauss algorithm (1) Iput k, i, a i, for i=1,2,,k N i j (2) Compute for i=1,2,,k j1, ji (3) Compute iverse 1 M N mod for i =1,2,,k i i i (4) Compute x k i1 a i N M i i mod p13.
Example x 1 mod 3 x 6 mod 7 x 8 mod10 Accordig to Gauss algorithm, x 1 70 (70 1 70 (1 1 1 mod 3) 6 30 (30 mod 3) 6 30 (2 1 70 1 6 30 4 8 211 958 mod 210 118 1 1 mod 7) 8 21 (21 mod 7) 8 21 (1 1 1 mod10) mod10) p14.
4. Square-ad-Multiply Algorithm: Square-ad-Multiply(x, c, ) Iput: Output: x Z x c mod z 1, c with biary represetatio c l 1 i0 c i 2 i for i l 1 dowto 0 do z z 2 mod if c i 1 the z (z x) mod retur ( z) p15.
Example : 9726 3533 mode 11413=? i c i z 11 1 1 2 x9726=9726 10 1 9726 2 x9726=2659 9 0 2659 2 =5634 8 1 5634 2 x9726=9167 7 1 9167 2 x9726=4958 6 1 4958 2 x9726=7783 5 0 7783 2 =6298 4 0 6298 2 =4629 3 1 4629 2 x9726=10185 2 1 10185 2 x9726=105 1 0 105 2 =11025 0 1 11025 2 x9726=5761 p16.
[2] Quadratic Residue 1. Quadratic residue modulo * Let a Z, the a is a quadratic residue modulo * 2 if there exists x Z with x a(mod). I this case, x is a square root of a modulo. Otherwise, a is a quadratic oresidue modulo. Q :the set of quadratic residues modulo. Q :the set of quadratic oresidues modulo. Z * Q Q p17.
2. Theorem :p > 2 is prime ad α is a geerator of Z p * a Z * p is a quadratic residue modulo p i Z s.t. a 2i (mod p) p18.
3. Corollary : p > 2 is prime ad α is a geerator of Z p * (1) (2) (3) (4) Q Qp Qp p { i mod p i eve, 0 i p 2} { i mod p i odd, 0 i p 2} Q p ( p 1)/ 2 If a Q, the 2 p x a(mod p) p1 2 1(mod p) has exactly two 4. Legedre symbol :p > 2 is prime ad a p 0 1 1 a p p a a mod p a mod p Q p Q p solutios. a Z p19.
5. Theorem :Euler s criterio a 2 p is prime ad a Z, the a p 6. E.g : 3 23? p1 (mod p) 23-1 1011 2 2 use Square-ad-Multiply 3 23 3 231 2 mod 23 1, so 3 Q 23 p20.
a 7. Jacobi symbol : > 2 is a odd iteger, p i is prime ad e p 1 1 e k p 1 a a p 1 e 1 a p k ek p21.
8. Properties of Jacobi symbol:m, > 2 are odd itegers (1) (2) a a { 1,0,1},ad 0 gcd( a,) 1 ab a b ad a m a m a (3) (4) If a b(mod) the 1 ad a 1 1 2 1 ( 1) b 1, 1, 1(mod4) 3(mod4) (5) (6) 2 1 8 ( 1) m m-1-1 m 2 1, 1, (-1) 2 2 1(mod8) 3(mod8) p22.
9. E.g :calculate Jacobi symbol without factorig a 28, 28 55 2 55 2 55 7 55 551 71 2 2 (property 2) 55 ( 1) (property 6) 7 55 6 (property 3) 7 7 7 1 71 2 ( 1) 1 (property 4) p23.
10. Jacobi symbol V.S. Quadratic residue modulo a 1 defiitio J a Q { a Z * a 1} The elemet of are called psedosquares modulo. Q ~ J,ad ~ Q J \ Q Q J i the case is prime. p24.
11. E.g :=15 a a a 15 3 5 ad a The Jacobi symbol * a Z 15 a 3 a 5 a 15 a 1, 1(mod3), 3 a 1, a 2(mod3), 1 1 1 1 2-1 -1 1 a 1, 1(mod5), 5 a 1, a 2(mod5). are calculated i the followig table: 4 1 1 1 7 8 1-1 -1-1 -1 1 11 13 ~ 15 15 Hece, J {1,2,4,8}. It ca be verfiedthat Q15 {1,4},theQ J15 \ Q15-1 1-1 1-1 -1 14-1 1-1 {2,8} p25.
12. Quadratic residuosity problem(qrp) Determie if a give a J is a quadratic residue or pseudosquare modulo p26.
[4] Primality Testig (1) Prime umbers 1. How to geerate large prime umbers? (1) Geerate as cadidate a radom odd umber of appropriate size. (2) Test for primality. (3) If is composite, retur to the first step. p27.
2. Distributio of prime umbers Prime Number Theorem Let Π(x) deote the umber of prime umbers x. Π(x) ~ x/l(x) whe. p28.
(2) Solovay-Strasse primality test 1. Trial method for testig is prime or composite a[ 2, ], if a does ot divide is prime 2. Defiitio :Euler witess Let be a odd composite iteger ad. (1) If 1 a gcd( a, ) 1 or ( 2 a a 1)/ (mod ) the a is a Euler witess (to compositeess) for. p29.
(2) Otherwise, if gcd( ( 2 a a, ) 1 ad a 1)/ (mod ) the is said to be a Euler pseudoprime to the base a. The iteger a is called a Euler liar (to primality) for. p30.
3. Example (Euler pseudoprime) Cosider = 91 (= 7x13) Sice 9 45 =1 mod 91, ad 9 91 1 so 91 is a Euler pseudoprime to the base 9. 4. Fact At most Φ()/2 of all the umbers a, are Euler liars for. p31.
5. Algorithm :Solovay-Strasse(, t) INPUT: is odd, 3, t 1 OUTPUT: prime or composite 1. for i = 1 to t do : 1.1 choose a radom iteger a, 2 a -2 if gcd(a,) 1 the retur ( composite ) 1.2 compute r=a (-1)/2 mod (use square-admultiply) if r 1 ad r -1 the retur ( composite ) 1.3 compute Jacobi symbol s= if r s the retur ( composite ) 2. retur ( prime ) a p32.
6. Solovay-Strasse error-probability boud For ay odd composite iteger, the probability that Solovay-Strasse (, t) declares to be prime is less tha (1/2) t p33.
(3) Miller-Rabi primality test 1. Fact P : odd prime p-1 = 2 s r, where r is odd an, gcd (a, p) = 1 the a r = 1 (mod ) or a 2j r = -1 (mod ) for some j, 0 j s-1 Why? (1) Fermat s little theorem, a p-1 = 1 mod p (2) 1, -1 are the oly two square roots of 1 i Z p * p34.
2. Defiitio : odd composite iteger -1 = 2 s r, where r is odd 1 a -1 a is a strog witess to compositeess for if a r 1 (mod ), ad a 2j r -1 (mod ) for all j, 0 j s-1 is a strog pseudoprime to the base a if a r = 1 (mod ) or a 2j r = -1 (mod ) for some j, 0 j s-1 (a is called a strog liar to primality for ) p35.
3. Algorithm: Miller-Rabi (, t) INPUT: is odd, 3, t 1 OUTPUT: prime or composite 1. write -1 = 2 s r such that r is odd. 2. for i = 1 to t do : 2.1 choose a radom iteger a, 2 a -2 2.2 compute y=a r mod (use square-ad-multiply) 2.3 if y 1 ad y -1 do : j 1 while j s-1 ad y -1 do : y y 2 mod if y = 1 the retur ( composite ) j j+1 3. retur ( prime ) if y -1 the retur ( composite ) p36.
4. Example (strog pseudoprime) Cosider = 91 (= 7x13) 91-1 = 2*45, s=1, r=45 Sice 9 r = 9 45 =1 mod 91, 91 is a strog pseudoprime to the base 9. The set of all strog liars for 91 is {1, 9, 10, 12, 16, 17, 22, 29, 38, 53, 62, 69, 74, 75, 79, 81, 82, 90} The umber of strog liars of for 91 is 18 = Φ(91)/4 p37.
5. Fact If is a odd composite iteger, the at most ¼ of all the umbers a, 1 a -1 are strog liars for. I fact if =!9, the umber of strog liars for is at most Φ()/4. p38.
6. Miller-Rabi error-probability boud For ay odd composite iteger, the probability that Miller-Rabi (, t) declares to be prime is less tha (1/4) t 7. Remark For most composite itegers, the umber of strog liars for is actually much smaller tha the upper boud of Φ()/4. Miller-Rabi error-probability boud is much smaller tha (1/4) t. p39.
(4) A determiistic primality algorithm: AKS Prior to 2002, there was o kow method of efficietly provig the primality of very large umbers. All the algorithms i use, icludig Solovay-Strasse ad Miller-Rabi, produced a probabilistic result. I 2002, Agrawal, Kayal, ad Saxea developed a relatively simple determistic algorithm, kow as AKS algorithm. But AKS does ot appear to be as efficiet as SS or MR. p40.