def pollard_pm1(N,B=0): if not B: B=ceil(sqrt(N)) a = Integers(N).random_element() b = a for ell in primes(B): q = 1 while q < N: q *= ell b = b^q if b == 1: return 0 d = gcd(b.lift()-1,N) if d > 1: return d return 0 def random_unsafe_prime(bits): while true: a=randint(0,bits) b=randint(0,floor((bits-a)/log(3,2))) c=randint(0,floor((bits-a-floor(b*log(3,2)))/log(5,2))) d=floor((bits-a-floor(b*log(3,2))-floor(c*log(5,2)))/log(7,2)) p = 2^a*3^b*5^c*7^d+1 if is_prime(p): return p
factor(random_unsafe_prime(512)-1)
p1=random_unsafe_prime(512) p2=random_prime(2^512,2^511) print(p1,p2) %time print(pollard_pm1(p1*p2))