0% found this document useful (0 votes)
8 views22 pages

Primality Testing Notes

The document discusses various methods and algorithms for primality testing, highlighting the challenges of testing large integers for primality. It introduces concepts such as Mersenne numbers, Fermat's and Euler's primes, and probabilistic algorithms, emphasizing that many tests yield a high probability of correctness rather than certainty. Additionally, it covers specific tests like the Fermat Primality Test and the Miller-Rabin Primality Test, along with the characteristics of composite numbers that can pass these tests.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views22 pages

Primality Testing Notes

The document discusses various methods and algorithms for primality testing, highlighting the challenges of testing large integers for primality. It introduces concepts such as Mersenne numbers, Fermat's and Euler's primes, and probabilistic algorithms, emphasizing that many tests yield a high probability of correctness rather than certainty. Additionally, it covers specific tests like the Fermat Primality Test and the Miller-Rabin Primality Test, along with the characteristics of composite numbers that can pass these tests.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

Primality Testing

Sachin Tripathi
IIT(ISM), Dhanbad
Introduction
 Suppose we have an integer of 200 digits that we want to test
for Primality.
 There are around 4×1097 primes less that 10100.
 This is significantly more that the number of particles in the
universe.
 Now, if the computer can handle 109 primes per second, the
calculation would take around 1081 years.
Generating Primes
 Several mathematicians attempt to develop a formula that
could generates primes.
 If p is a prime number then, Mp= 2p–1
 A number in the form Mp= 2p–1 is called a Mersenne
number.
 All numbers are not a prime.
Example
 M2= 22–1 = 3
 M3= 23–1 = 7
 M5= 25–1 = 31
 M7= 27–1 = 127
 M11= 211–1 = 2047 (23×89)
 M13= 213–1 = 8191
 M17= 217–1 = 131071
Fermat’s Prime F  22  1 n

n
 If n is an integer then,
 F2= 17
 F3= 257
 F4= 65537
 F5= 429467297 is not a prime (641×6700417)
Euler’s Prime
 If n is an integer then Euler’s prime generating polynomial
P(n )is defined as follows:
P(n) = 𝑛2+𝑛+41
 P(1) = 43
 P(2) = 47
Finding Large Primes in RSA
 The general approach is to generate large integers at random
which are then checked for primality.
Divisibility Algorithm
Problem Statement: Given a number n, how can we determine if
n is a prime?
Answer: The answer is that we need to see if the number is divisible
by all primes less than n.

January 6, 2025
Probabilistic Algorithms
 Most of the efficient algorithms for Primality testing are
category of probabilistic algorithm.
 A probabilistic algorithm does not guarantee the correctness
of the result.
 However, we can make the probability of error so small that
it is almost certain that the algorithm has returned a correct
answer.
Primality Tests
 Practical primality tests behave somewhat unusually: if the
integer p in question is being fed into a primality test
algorithm, then the answer is either
1. “p is composite” (i.e., not a prime), which is always a true statement,
or
2. “p is prime”, which is only true with a high probability.
Common Practice
 If the algorithm output is “composite”, the situation is clear:
The integer in question is not a prime and can be discarded.
 If the output statement is “prime”, p is probably a prime. In
rare cases, it yields an incorrect positive answer.
 Practical primality tests are probabilistic algorithms.
Fermat Primality Test
 Let n>1 be an integer. Choose a random integer a with
n1
1<a<n-1. If a  1mod n then n is composite. Otherwise
n is probably prime.
 There are certain composite integers which behave like primes in the
Fermat test for many values of a.
 For example 561 (3×11×17) passes the Fermat test.
 These are the Carmichael numbers. A Carmichael number must
be the product of at least three distinct primes.
 Such special composites are very rare. For instance, there
exist approximately only 100,000 Carmichael numbers below 1015.
Square Root Primality Test

 In Modular Arithmetic ,if n is a prime , the square root of 1 is either


+1 or -1.
 If n is composite ,the square root is +1 or -1 but there may be
other roots.
 What are the square roots of 1 mod n if n is 7 (a prime)?
 Solution: The only square roots are 1 and −1.

 What are the square roots of 1 mod n if n is 8 (a composite)?


 Solution: There are four solutions: 1, 3, 5, and 7 (which is −1).
 What are the square roots of 1 mod n if n is 22 (a
composite)?
 Solution: Surprisingly, there are only two solutions, +1 and
−1, although 22 is a composite.
Contd…
 Although this test can tell us if a number is composite, it is
difficult to do the testing.
 Given a number n, all numbers less than n (except 1 and n-1)
must be squared to be sure that none of them is 1.
 This test can be used for a number (not +1 or -1) that when
squared in modulus n has the value 1.
 This fact helps in the Miller-Rabin test.
Miller-Rabin PrimalityTest
Example
Thank You
22 Dept. of CSE, IIT(ISM) Dhanbad January 6, 2025

You might also like