Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 123
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 d = gcd(b.lift()-1,N) if d == N: return 0 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)
2^498 * 5^4 * 7
%time p1=random_unsafe_prime(512) p2=random_prime(2^512,2^511) print p1,p2 print pollard_pm1(p1*p2)
21706676832128726214608944620224562112527996020332443314603139337093314863115929858598907429802497850507183138648400064512000000000000000000000000000000001 3679659102042840868733274403461061134317440053298234376444111326564082563891568703709569635033385872645959431747280998736693541792048085481849656348406717 21706676832128726214608944620224562112527996020332443314603139337093314863115929858598907429802497850507183138648400064512000000000000000000000000000000001 CPU time: 0.68 s, Wall time: 0.68 s