0% found this document useful (0 votes)
61 views5 pages

Primality Testing

The document discusses primality testing algorithms. It explains that determining whether a given large number is prime is an important problem in cryptography. It then describes the Miller-Rabin randomized primality test algorithm, which takes a candidate number n as input and returns either "composite" if n is definitely not prime or "inconclusive" if n may or may not be prime. The algorithm is demonstrated through examples, showing it correctly identifying 29 as a possible prime and 221 as definitely composite.
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)
61 views5 pages

Primality Testing

The document discusses primality testing algorithms. It explains that determining whether a given large number is prime is an important problem in cryptography. It then describes the Miller-Rabin randomized primality test algorithm, which takes a candidate number n as input and returns either "composite" if n is definitely not prime or "inconclusive" if n may or may not be prime. The algorithm is demonstrated through examples, showing it correctly identifying 29 as a possible prime and 221 as definitely composite.
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/ 5

Primality Testing

 Primality testing is an important algorithmic problem.


 The problem of how to determine whether a given number is prime has
tremendous practical importance.
 For many cryptographic algorithms, it is necessary to select one or more
very large prime numbers at random.
 Thus, we are faced with the task of determining whether a given large
number is prime.
 Monte-Carlo randomization algorithm – does not guarantee correct
result. But probability of incorrect result is very small.

Miller-Rabin Randomized Primality Test

The procedure TEST takes a candidate integer n as input and returns the result
composite if n is definitely not a prime, and the result inconclusive if n may or
may not be a prime.
Prime Numbers and Pseudo Prime Numbers
Numerical Examples
1. Conduct primality test for n = 29.
n = 29
n – 1 = 28
n – 1 = 2k.q = 22.7 where, [k = 2, q = 7]
select random integer a such that 1 < a < 28
Hence, a value can be from 2 to 27

Let a = 10;
Compute aq mod n = 107 mod 29 = 17 -------- condition is false
For loop begins. For j = 0 to k-1 = 0 to 1
For each value of j check whether a2^j.q mod n = n-1
When j = 0, a2^j.q mod n = 102^0.7 mod 29 = 101.7mod 29 = 107 mod 29 = 17
Condition is false
Next iteration of j loop begins
When j = 1, a2^j.q mod n = 102^1.7 mod 29 = 102.7mod 29 = 1014 mod 29 = 28
Condition is true.
Algorithm returns “inconclusive” (i.e., 29 may be prime).

Try with a = 2

Let a = 2;
Compute aq mod n = 27 mod 29 = 12 -------- condition is false
For loop begins. For j = 0 to k-1 = 0 to 1
For each value of j check whether a2^j.q mod n = n-1
When j = 0, a2^j.q mod n = 22^0.7 mod 29 = 21.7mod 29 = 27 mod 29 = 12
Condition is false
Next iteration of j loop begins
When j = 1, a2^j.q mod n = 22^1.7 mod 29 = 22.7mod 29 = 214 mod 29 = 28
Condition is true.
Algorithm returns “inconclusive” (i.e., 29 may be prime).

If we perform the test for all integers a in the range from 2 to through 27, we
get the same inconclusive result, which is compatible with n being a prime
number.

2. Conduct primality test for n = 221


n = 221
n – 1 = 220
n – 1 = 2k.q = 22.55 where, [k = 2, q = 55]
select random integer a such that 1 < a < 220
Hence, a value can be from 2 to 219

Let a = 5;
Compute aq mod n = 555 mod 221 = 112 -------- condition is false
For loop begins. For j = 0 to k-1 = 0 to 1
For each value of j check whether a2^j.q mod n = n-1
When j = 0, a2^j.q mod n = 52^0.55 mod 221 = 51.55mod 221 = 555mod 221 = 112
Condition is false
Next iteration of j loop begins
When j = 1, a2^j.q mod n = 52^1.55 mod 221 = 52.55mod 221 = 5110 mod 221 = 168
Condition is false.
For loop terminates.
Algorithm returns “composite” (i.e., 221 is definitely a composite).
Try with a = 21
Let a = 21;
Compute aq mod n = 2155 mod 221 = 200 -------- condition is false
For loop begins. For j = 0 to k-1 = 0 to 1
For each value of j check whether a2^j.q mod n = n-1
When j = 0, a2^j.q mod n = 212^0.55 mod 221 = 211.55mod 221 = 2155mod 221 =
200
Condition is false
Next iteration of j loop begins
When j = 1, a2^j.q mod n = 212^1.55 mod 221 = 212.55mod 221 = 21110 mod 221 =
220
Condition is true.
Algorithm returns “inconclusive” (i.e., 221 may be prime).

In fact, of the 218 integers from 2 through 219, four of these will return an
inconclusive result, namely 21, 47, 174, and 200.

You might also like