Primality: Naïve Test
17 Dec 2021
§ Motivation
RSA is dependent on very large primes and it is not practical to have a lookup table of very large primes, so we must find a way to generate primes. We can do this by generating a random odd number then testing if it is prime.
§ Naïve Test
Naïve Test
Suppose we want to determine primality of an odd integer . We can do trial division for all integers in .
- If , then we can stop and say that is composite, otherwise we continue to the next value of .
- If we have exhausted all integers in the interval, then is prime.
§ Complexity Discussion
This naïve test has a time complexity of , however, this does not mean it is an efficient algorithm. Consider the input to the algorithm: a number. Next, we can think of a number as a sequence of digits, and it follows that the number of elements in this sequence is . There exists no polynomial such that , therefore, this naïve algorithm is does not run in polynomial time.
In RSA, we deal with numbers exceeding , and given time complexity, we can expect about trial divisions to determine primality using this method.
For illustrative purposes, suppose that , i.e. is the size of the input. If we had an time algorithm for primality, then we can expect about steps to determine if a number around is prime. This is significantly smaller than the bound from the naïve test.