Pollard's p-1
Factorising N when we know a factor is smooth
Last updated
Factorising N when we know a factor is smooth
Last updated
If we say that , where are prime, then we can also say that for any :
Due to Fermat's Little Theorem. This would mean is a factor of and therefore .
Let us say that . If , then . Since , we know that .
This may seem all well and good, but how does this help us? We don't know , nor do we have a way of calculating .
What we actually do here is guess the value of by (effectively) brute force. Essentially we put to the power of integers with a huge number of prime factors, so it's all the more likely that the factors of are there. Once we put it to the powers, we can calculate the and if it is not equal to then we have factorised successfully.
The most common technique is to calculate and then calculate the GCD from there. We can make this into a more efficient approach by repeatedly putting it to the power of one greater than the previous iteration, e.g. calculate and calculate the GCD each time - this way, we will have a wealth of factors. A common choice of is .
Let's try and factorise using Pollard's :
We can implement this algorithm really easily in Sage:
You can remove the print()
functions as they are completely unneccessary, but the logging may help visualise what it does.
We get to , and find that . We have successfully factorised !
This algorithm is useful when we know is smooth, meaning it has lots of small prime factors. If this is the case, the iterative approach is more likely to include sooner rather than later. This leads to the concept of safe primes, primes in the form where is also a prime (called a Sophie Germain prime). In this case, is not smooth.