Date post: | 06-Apr-2018 |
Category: |
Documents |
Upload: | akhilesh-chaganti |
View: | 235 times |
Download: | 0 times |
of 33
8/3/2019 Rabin Miller Primality Test
1/33
Motivation Algorithm Conclusion References
Rabin Miller Probabilistic Primality
Test
Akhilesh Chaganti,Shafiuddin Rehan AhmedGautham Raj G,Pattabi Ramiah
Indian Institute of Technology Hyderabad
November 29, 2010
-Typeset by LATEX-
http://goforward/http://find/http://goback/8/3/2019 Rabin Miller Primality Test
2/33
Motivation Algorithm Conclusion References
Contents
1 Motivation
Cryptography - Encryption mechanismsThe properties of numbersThe element of randomization
http://goforward/http://find/http://goback/8/3/2019 Rabin Miller Primality Test
3/33
Motivation Algorithm Conclusion References
Contents
1 Motivation
Cryptography - Encryption mechanismsThe properties of numbersThe element of randomization
2 Algorithm
definitionInterpretation of the algorithmPseudocodeExpected Running Time
Error BoundsImplementationWitnessing and Non Witnessing
http://goforward/http://find/http://goback/8/3/2019 Rabin Miller Primality Test
4/33
Motivation Algorithm Conclusion References
Contents
1 Motivation
Cryptography - Encryption mechanismsThe properties of numbersThe element of randomization
2 Algorithm
definitionInterpretation of the algorithmPseudocodeExpected Running Time
Error BoundsImplementationWitnessing and Non Witnessing
3 Conclusion
M i i Al i h C l i R f
http://goforward/http://find/http://goback/8/3/2019 Rabin Miller Primality Test
5/33
Motivation Algorithm Conclusion References
Contents
1 Motivation
Cryptography - Encryption mechanismsThe properties of numbersThe element of randomization
2 Algorithm
definitionInterpretation of the algorithmPseudocodeExpected Running Time
Error BoundsImplementationWitnessing and Non Witnessing
3 Conclusion
4 References
M ti ti Al ith C l i R f
http://goforward/http://find/http://goback/8/3/2019 Rabin Miller Primality Test
6/33
Motivation Algorithm Conclusion References
Cryptography - Encryption mechanisms
Cryptography is a very important and heavily growing branch ofcomputer science which is based on number theory. The famousproblem of this field is the public key encryption mechanismswhich is used extensively in network security.
Motivation Algorithm Conclusion References
http://goforward/http://find/http://goback/8/3/2019 Rabin Miller Primality Test
7/33
Motivation Algorithm Conclusion References
Cryptography - Encryption mechanisms
Cryptography is a very important and heavily growing branch ofcomputer science which is based on number theory. The famousproblem of this field is the public key encryption mechanismswhich is used extensively in network security.
The main way of implementing this encryption mechanism is tointroduce the notion of a one-way function. It can interpreted as afunction which is easy to compute and very hard to compute backits inverse.
Motivation Algorithm Conclusion References
http://goforward/http://find/http://goback/8/3/2019 Rabin Miller Primality Test
8/33
Motivation Algorithm Conclusion References
Cryptography - Encryption mechanisms
Cryptography is a very important and heavily growing branch ofcomputer science which is based on number theory. The famousproblem of this field is the public key encryption mechanismswhich is used extensively in network security.
The main way of implementing this encryption mechanism is tointroduce the notion of a one-way function. It can interpreted as afunction which is easy to compute and very hard to compute backits inverse.
An important implementation of the public key encryption systemis based on a conjecture of multiplying two prime numbers as aone way function
Motivation Algorithm Conclusion References
http://goforward/http://find/http://goback/8/3/2019 Rabin Miller Primality Test
9/33
Motivation Algorithm Conclusion References
The properties of numbers
Till date it is observed that the multiplication of two very largeprime numbers is almost a one-way process i.e. it is easy to get theproduct of numbers but computing the prime factors for a given(large) number is hard. This provides motivation for the primalitytesting of a (large) number which can be inturn used in encryption
mechanisms.
Motivation Algorithm Conclusion References
http://goforward/http://find/http://goback/8/3/2019 Rabin Miller Primality Test
10/33
Motivation Algorithm Conclusion References
The properties of numbers
Till date it is observed that the multiplication of two very largeprime numbers is almost a one-way process i.e. it is easy to get theproduct of numbers but computing the prime factors for a given(large) number is hard. This provides motivation for the primalitytesting of a (large) number which can be inturn used in encryption
mechanisms.
Is the problem of primality testing easy (deterministic polynomialtime algorithm)??
Motivation Algorithm Conclusion References
http://goforward/http://find/http://goback/8/3/2019 Rabin Miller Primality Test
11/33
Moti ation lgorithm Conclusion References
The properties of numbers
Till date it is observed that the multiplication of two very largeprime numbers is almost a one-way process i.e. it is easy to get theproduct of numbers but computing the prime factors for a given(large) number is hard. This provides motivation for the primalitytesting of a (large) number which can be inturn used in encryption
mechanisms.
Is the problem of primality testing easy (deterministic polynomialtime algorithm)??
Yes. In 2002, 3 Indians(@ IIT Kanpur) proposed an algorithm (TheAKS algorithm) which tests the primality of the given number n in
the order of O(log152 n)
Motivation Algorithm Conclusion References
http://goforward/http://find/http://goback/8/3/2019 Rabin Miller Primality Test
12/33
g
The properties of numbers
Till date it is observed that the multiplication of two very largeprime numbers is almost a one-way process i.e. it is easy to get theproduct of numbers but computing the prime factors for a given(large) number is hard. This provides motivation for the primalitytesting of a (large) number which can be inturn used in encryption
mechanisms.
Is the problem of primality testing easy (deterministic polynomialtime algorithm)??
Yes. In 2002, 3 Indians(@ IIT Kanpur) proposed an algorithm (TheAKS algorithm) which tests the primality of the given number n in
the order of O(log152 n)
NOTE: The standard measure of the complexity of the number
theoritic algorithms is reffered to bit complexity.
Motivation Algorithm Conclusion References
http://goforward/http://find/http://goback/8/3/2019 Rabin Miller Primality Test
13/33
The element of randomization
Since, there is no real time efficient algorithm for primality testingwe see the need for randomization.There are several randomized
algorithms testing primality of number with certain confidence(with a controllably small probability of error.)
Motivation Algorithm Conclusion References
http://goforward/http://find/http://goback/8/3/2019 Rabin Miller Primality Test
14/33
The element of randomization
Since, there is no real time efficient algorithm for primality testingwe see the need for randomization.There are several randomized
algorithms testing primality of number with certain confidence(with a controllably small probability of error.)
One such algorithm is
Rabin Miller Probabilistic Primality test.
Motivation Algorithm Conclusion References
http://goforward/http://find/http://goback/8/3/2019 Rabin Miller Primality Test
15/33
Rabin-Miller Primality Test
Definition
Given (b,n), where n is the number to test for the primality, and bis randomly chosen from Zn-{0}. Let n-1 = 2
qm, where m is an
odd integer. if eitherbm 1(mod n) or
there is an integer i in [0,q-1] such that bm2i
-1(mod n)
then return probabily prime else return composite
NOTE : Rabin-Miller is a Monte Carlo algorithm: there is anonzero probability of error.
Motivation Algorithm Conclusion References
http://goforward/http://find/http://goback/8/3/2019 Rabin Miller Primality Test
16/33
Interpretation of the Algorithm
The algorithm enables one to probabilistically test the primality ofa number n as follows:
If n fails the test(i.e. results in n is composite) for any b in[1,n-1] then n is definitely composite (although, interestingly,no factor is provided by the algorithm).
A composite number has at most 1 chance in 4k of passing allk of a series of k tests, where b is chosen randomly from [ 1 ,n - 1 ] for each test. Therefore, if a suspected prime, n, passesk of k tests, we can conclude with a certainty of at least 1 -
(1/4)k
that n is prime.
NOTE: Rabin-Miller Test is co-RP-algorithm for testing theprimality of the given number
PRIMES
co-RP
Motivation Algorithm Conclusion References
http://goforward/http://find/http://goback/8/3/2019 Rabin Miller Primality Test
17/33
Pseudocode
Pseudocode
Input: n 4, an odd integer to be tested for primality;Input: k, a parameter that determines the accuracy of the testOutput: composite if n is composite, otherwise probably primewrite n 1 as 2sd with d odd by factoring powers of 2 from n 1
LOOP: repeat k times:pick a randomly in the range [2, n 2]x ad mod nif x = 1 or x = n 1 then do next LOOPfor r = 1 .. s1
x x2 mod nif x = 1 then return compositeif x = n 1 then do next LOOPreturn composite
return probabily prime
Motivation Algorithm Conclusion References
http://goforward/http://find/http://goback/8/3/2019 Rabin Miller Primality Test
18/33
Expected Running Time
Running Time
Using modular exponentiation by repeated squaring, the runningtime of this algorithm is O(k log3 n), where k is the number ofdifferent values of a we test; thus this is a reasonably efficientpolynomial-time algorithm when compared the deterministic one.
Motivation Algorithm Conclusion References
http://goforward/http://find/http://goback/8/3/2019 Rabin Miller Primality Test
19/33
Coming back to the bound. . .
The algorithm enables one to probabilistically test the primality ofa number n as follows:
If n fails the test(i.e. results in n is composite) for any b in
[1,n-1] then n is definitely composite (although, interestingly,no factor is provided by the algorithm).
A composite number has at most 1 chance in 4k of passing allk of a series of k tests, where b is chosen randomly from [ 1 ,n - 1 ] for each test. Therefore, if a suspected prime, n, passesk of k tests, we can conclude with a certainty of at least 1 -(1/4)k that n is prime.
Motivation Algorithm Conclusion References
http://goforward/http://find/http://goback/8/3/2019 Rabin Miller Primality Test
20/33
Implementation on a known prime
We will now demonstrate this algorithm on a number that wedefinitely know is prime.Lets take n = 29.
Motivation Algorithm Conclusion References
http://goforward/http://find/http://goback/8/3/2019 Rabin Miller Primality Test
21/33
Implementation on a known prime
We will now demonstrate this algorithm on a number that wedefinitely know is prime.Lets take n = 29.
So n-1 = 28, which can be written as 22.7So, here q = 2 and m = 7. Take b = 10.
Motivation Algorithm Conclusion References
http://goforward/http://find/http://goback/8/3/2019 Rabin Miller Primality Test
22/33
Implementation on a known prime
We will now demonstrate this algorithm on a number that wedefinitely know is prime.Lets take n = 29.
So n-1 = 28, which can be written as 22.7So, here q = 2 and m = 7. Take b = 10.Applying the algorithm107 17 (mod 29) which is not congruent to 1 or -1.So,we continue the test.
Motivation Algorithm Conclusion References
http://goforward/http://find/http://goback/8/3/2019 Rabin Miller Primality Test
23/33
Implementation on a known prime
We will now demonstrate this algorithm on a number that wedefinitely know is prime.Lets take n = 29.
So n-1 = 28, which can be written as 22.7So, here q = 2 and m = 7. Take b = 10.Applying the algorithm107 17 (mod 29) which is not congruent to 1 or -1.So,we continue the test.
(107)2 -1(mod 29) Inconclusive state
Motivation Algorithm Conclusion References
http://goforward/http://find/http://goback/8/3/2019 Rabin Miller Primality Test
24/33
Implementation on a known composite
We will now demonstrate this algorithm on a number that wedefinitely know is composite.Lets take n = 13 7 = 221.
Motivation Algorithm Conclusion References
http://goforward/http://find/http://goback/8/3/2019 Rabin Miller Primality Test
25/33
Implementation on a known composite
We will now demonstrate this algorithm on a number that wedefinitely know is composite.Lets take n = 13 7 = 221.n-1 = 220 = 22 55, here q = 2 and m = 55. Take b = 5.
Motivation Algorithm Conclusion References
http://goforward/http://find/http://goback/8/3/2019 Rabin Miller Primality Test
26/33
Implementation on a known composite
We will now demonstrate this algorithm on a number that wedefinitely know is composite.Lets take n = 13 7 = 221.n-1 = 220 = 22 55, here q = 2 and m = 55. Take b = 5.Applying this algorithm
for i = 0, 555 112 (mod 221) = 1 or -1 (mod 221).So, lets take i = 1, (555)2 168 (mod 221) = -1 (mod 221)
Motivation Algorithm Conclusion References
http://goforward/http://find/http://goback/8/3/2019 Rabin Miller Primality Test
27/33
Implementation on a known composite
We will now demonstrate this algorithm on a number that wedefinitely know is composite.Lets take n = 13 7 = 221.n-1 = 220 = 22 55, here q = 2 and m = 55. Take b = 5.Applying this algorithm
for i = 0, 555 112 (mod 221) = 1 or -1 (mod 221).So, lets take i = 1, (555)2 168 (mod 221) = -1 (mod 221)After using all the values of i, we are still in a false case. So wecan definitely say its a composite number.
Motivation Algorithm Conclusion References
http://goforward/http://find/http://goback/8/3/2019 Rabin Miller Primality Test
28/33
Implementation on a known composite
We will now demonstrate this algorithm on a number that wedefinitely know is composite.Lets take n = 13 7 = 221.n-1 = 220 = 22 55, here q = 2 and m = 55. Take b = 5.Applying this algorithm
for i = 0, 555 112 (mod 221) = 1 or -1 (mod 221).So, lets take i = 1, (555)2 168 (mod 221) = -1 (mod 221)After using all the values of i, we are still in a false case. So wecan definitely say its a composite number.
However, if b = 21.Then (21)55 200 (mod 221) which is not congruent to 1 or -1.So we continue the test. We obtain (2155)2 -1 (mod 221) Thatis for a composite number 221 which is inconclusive.
Motivation Algorithm Conclusion References
http://goforward/http://find/http://goback/8/3/2019 Rabin Miller Primality Test
29/33
Implementation on a known composite
We will now demonstrate this algorithm on a number that wedefinitely know is composite.Lets take n = 13 7 = 221.n-1 = 220 = 22 55, here q = 2 and m = 55. Take b = 5.Applying this algorithm
for i = 0, 555 112 (mod 221) = 1 or -1 (mod 221).So, lets take i = 1, (555)2 168 (mod 221) = -1 (mod 221)After using all the values of i, we are still in a false case. So wecan definitely say its a composite number.
However, if b = 21.Then (21)55 200 (mod 221) which is not congruent to 1 or -1.So we continue the test. We obtain (2155)2 -1 (mod 221) Thatis for a composite number 221 which is inconclusive.We call such a base a non-witness to the compositeness of 221.
Motivation Algorithm Conclusion References
http://goforward/http://find/http://goback/8/3/2019 Rabin Miller Primality Test
30/33
Witnessing and non witnessing bases
Non-Witness
The base b in [1,n-1] results in inconclusive for a compositenumber, then b is a non-witness to the compositness of n.
example
For 221, we have six non-witnesses namely 1 , 21 , 47 , 174 , 200and 220.
We denote number of non-witnesses of n by nw(n). So, in ourexample nw(221) = 6.
Motivation Algorithm Conclusion References
http://goforward/http://find/http://goback/8/3/2019 Rabin Miller Primality Test
31/33
Rabin stated that the number witness to compostiness has a lowerbound.
Theorem
If n > 4 is composite, then the number of bases, b, in [1, n-1] suchthat b is a witness to the compositeness of n is at least 3 (n-1) / 4.
The following corollary describing the upper bound onnon-witnesses to compositeness follows directly from theorem 1.
Corollary
If n > 4 is composite then at most (n-1) / 4 of the bases, b, in [1,
n-1] are non-witnesses to the compositeness of n.
Thus, we can get a bound on probability of passing the statementfalse, even when the number is actually composite as 1/4.
Motivation Algorithm Conclusion References
http://goforward/http://find/http://goback/8/3/2019 Rabin Miller Primality Test
32/33
Conclusion
conclusions and Remarks
Although, there are number of primality tests, Rabin-Millertest is the most commonly used.
Compared to any other test which provides the confidence asmuch as Rabin-Miller test, it is the test which can beimplemented with ease and that to in O(n3)
Rabin-Miller test also produces pseudo primes but notabsolute pseudo primes like Fermat and Euler tests for
primality. So definitely better than the above testThere are also deterministic variants of the test assuming thetruth of unproven Generalized Riemann Hypothesis.
Motivation Algorithm Conclusion References
http://goforward/http://find/http://goback/8/3/2019 Rabin Miller Primality Test
33/33
References
[Motwani R.,Raghavan P.]Randomized Algorithms , ISBN 0-521-61390-6
[Brian C. Higgins]The Rabin-Miller Primality Test : Some results on number ofnon-witnesses to compositeness.
[Rabin Miller Primality test]
http://en.wikipedia.org/
http://en.wikipedia.org/wiki/Rabin-Miller_primality_testhttp://en.wikipedia.org/wiki/Rabin-Miller_primality_testhttp://goforward/http://find/http://goback/