I am a student in college and have an assignment which requires finding large prime numbers. I was given the following "simple" algorithm by the professor to find 2 likely prime numbers.
- generate random a and p where 1 < a < p
- confirm that gcd(a,p) is = 1 -- this is suppose to remove Carmichael numbers Edit(meant equal to 1)
- perform "modular exponentiation" if x ^ (p-1) % p = 1 where x begins at zero and increments up to p-1 for both p and a
Example of the 3rd step.
suppose p = 5
1^4 %5 = 1
2^4 %5 = 1
3^4 %5 = 1
4^4 %5 = 1
This shows that 5 is prime.
I am realizing through this assignment that computing prime numbers is no joke. The problem I see with the above algorithm is that if I am guessing large numbers and testing them with the modular exponentiation, I could be attempting to raise a large number to a large number. This places a doubt in my mind. I have looked into Deterministic Finite Automata and the Sieve of Eratosthenes as well. Does anyone have any suggestions to either improve the given algorithm or provide any kind of assistance? Thank you for time.