Fundamental number theory with applications (Richard A. Mollin)

Page 130

2.7. Primality Testing

2.7

119

Primality Testing

Probable impossibilities are to be preferred to improbable possibilities. From Chapter 24 of Poetics Aristotle (384–322 B.C.), Greek philosopher We now have the tools at our disposal to continue the study of primality testing begun in §1.8, where we looked at only true primality tests. We will look at not only more such tests, but also some probabilistic primality tests, which are primality tests that use randomized algorithms, namely those that make random decisions at certain points in their execution, so that the execution paths may differ each time the algorithm is invoked with the same input. Therefore, a probabilistic primality test will provide good, but not necessarily conclusive evidence that a given input is prime. For instance, the following probabilistic primality test will answer correctly if a prime is input, but might err with very small probability if the input is composite. (See Biographies 2.10 on page 122, 2.9 on page 121, and 2.11 on page 123.) The following is adapted from [32]. Note that we assume we have a method of generating “random numbers.” In §3.4 we will learn how to do this in detail. ◆ The Miller-Selfridge-Rabin (MSR) Primality Test Let n − 1 = 2t m where m ∈ N is odd and t ∈ N. The value n is the input to be tested by executing the following steps, where all modular exponentiations are done using the repeated squaring method described on page 82. (1) Choose a random integer a with 2 ≤ a ≤ n − 2. (2) Compute If

x0 ≡ am (mod n). x0 ≡ ±1 (mod n),

then terminate the algorithm with

“n is probably prime.” If x0 $≡ ±1 (mod n) and t = 1, terminate the algorithm with “n is definitely composite.” Otherwise, set j = 1 and go to step (3). (3) Compute xj ≡ a2

j

m

(mod n).

If xj ≡ 1 (mod n), then terminate the algorithm with “n is definitely composite.”


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.