Primality Testing Notes
Primality Testing Notes
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
n1
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