Pollard's p-1

Factorising N when we know a factor is smooth

Overview

Example

Applications

Sage Code

We can implement this algorithm really easily in Sage:

def pollards(n, iterations=50):
    R = IntegerModRing(n)
    cur = R(2)
    
    for i in range(2, iterations):
        print(f'{cur} ^ {i} = {cur**i}')
        
        cur **= i
        tst = gcd(cur-1, n)
        
        print(f'gcd({cur-1}, {n}) = {tst}')
        
        if tst != 1:
            return tst
    else:
        return None

You can remove the print() functions as they are completely unneccessary, but the logging may help visualise what it does.

Last updated