The RSA cryptosystem needs a pair of large primes. The algorithm acquires them by:
where the Witness(a, n) subroutine is:
Repeat s times { Pick a random integer a between 1 and n-1. If Witness( a, n ) (i.e., if a is a witness for the non-primality of n) return not-prime (definitely!) } Return prime (almost surely!)
Write n-1 as bk bk-1 bk-2 … b1 b0. d := 1 for i := k downto 0 { oldD := d d := d * d mod n if d == 1 and oldD != 1 and oldD != n-1 return true (a is a witness to the non-primality of n) if ( bi == 1 ) d := d * a mod n } if d != 1 return true (a is a witness to the non-primality of n) else return false (a is not a witness, maybe n is prime)
Miller-Rabin is correct and fast because:
Provide empirical evidence for the truth of each of the above claims by using a procedure that is something like this:
This theorem says that if we choose a large-enough random integer n, the probability that it is prime is about 1 / log n. It follows that about log n random choices will, on average, yield a prime number.
Let P(n) denote the number of primes less than or equal to n. Then
The limit as n goes to infinity of P(n)
nlog n is 1.
Provide empirical evidence for the truth of the Prime Number Theorem by computing P(n) for each integer n from 2 to ... (Go as far as you can in a reasonable amount of computing time.)
Diplay your results by graphing both
P(n) n |
and | 1 log n |
You may use any algorithm you wish for primality-testing (deterministic or randomized).
This problem is VERY easy in Maple because:
x &^ (-1) mod y