def lenstra(n, limit):
g = n
while g == n:
# Randomized x and y
q = randint(0, n - 1), randint(0, n - 1), 1
# Randomized curve coefficient a, computed b
a = randint(0, n - 1)
b = (q[1] * q[1] - q[0] * q[0] * q[0] - a * q[0]) % n
g = gcd(4 * a * a * a + 27 * b * b, n) # singularity check
# If we got lucky, return lucky factor
if g > 1:
return g
# increase k step by step until lcm(1, ..., limit)
for p in primes(limit):
pp = p
while pp < limit:
q = elliptic_mul(p, q, a, b, n)
# Elliptic arithmetic breaks
if q[2] > 1:
return gcd(q[2], n)
pp = p * pp
return False
# Command line tool
评论列表
文章目录