2.1.1. Implementation Randomly select an odd integer n to be tested as a prime Randomly select an integer a that is 1 ≤ a ≤ n Calculate the Jacobi Symbol (a/n) using the aforementioned properties Check if the relation a^((n-1)/2)≡(a/n) holds. If it does, go to step 2. Repeat the process k times If not, n is not prime. Go to step 1.
At the end of this algorithm, a number n which is likely to be prime is returned, the probability of which is 1/2^k since the probability of a number being prime or not prime is 1/2 and the test is done k times.
Additionally, certain criteria must be fulfilled by the implementation: n must be larger than 2 and also sufficiently large (2048 bit) to be useful in RSA encryption n can only be an odd number
…show more content…
Thus I rewrote the program to accomadate numbers what were 2048-bit using a built-in class of Java called BigInteger, which has no (theoretical) limits to the size of a number. The number on aligned vertically on this page is the result of a test with only one iteration and took 15 seconds. I checked this result with a built-in probable-prime generator of BigInteger, which uses the Miller-Rabin primality test (which we will come back to in the Miller-Rabin section). Since both tests I used are probabilistic, although we cannot say for sure this number is prime, it is a pseudo-prime.
The original long integer implementation of Solovay-Strassen I used was written in around 100 lines of code and my rewritten one in a little over 160 lines. It was also fairly easy to write and can be done with anyone of adequate knowledge of Java, should they choose to use BigInteger, and modular arithmetic. Additionally, both the original and my implementation of the Solovay-Strassen test aren’t the most efficient and there is plenty of room for optimisation, making the 2048-bit version a possible option for generating RSA
…show more content…
Otherwise discard a and redo test. return false, n is probably prime.
Similar to the Solovay-Strassen test, Fermat pseudo-primes exist where a^(n-1)≡1 (mod n) is true for n for the base a. A prime number would therefore be a Fermat pseudo-prime where the theorem holds for all bases a.
This means that it cannot be said with certainty that a Fermat pseudo-prime n for base a is actually prime, only co-prime. The algorithm therefore checks whether the theorem does not hold and returns true when the number is composite. The more number of bases n is checked against, the more certain we can be that it is prime.
The Miller-Rabin test is based on Fermat’s little theorem, with several optimizations. Similar to the Solovay-Strassen test, even numbers are discarded are these cannot be primes anyway and decreases the number of possible misdetections. Implementation Select a random odd integer n>2 Select the number of times k we want to run the test Select a random integer a between the range of 1≤a≤n-1 Rewrite n-1 as 2^s q, where q is an odd