Skip to content

Instantly share code, notes, and snippets.

@andreuinyu
Created October 28, 2014 19:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andreuinyu/d98c12f81c49e2df4e85 to your computer and use it in GitHub Desktop.
Save andreuinyu/d98c12f81c49e2df4e85 to your computer and use it in GitHub Desktop.
Animation of Hendrik Lenstra's Elliptic Curve Factorization checking the primality of an integer
n = 1997 #must be prime: defines the field Z/nZ
k = 720719 #the point (0, 1) is "multiplied" by k
coeff = 23 #coefficient of "x" in the elliptic curve
x, y = var('x y')
E = EllipticCurve(GF(n),[coeff,1])
llistapunts = []
frames = []
tamany = 40
marc = implicit_plot(x-y^3, (x, 0, n-1), (y, 0, n-1), color = 'white', gridlines = True)
tamanyextra = tamany + tamany//2
def cart(A):
return (A[0]/A[2], A[1]/A[2])
P = E([0, 1])
puntPextra = point(cart(P), color = 'blue', size = tamanyextra)
puntP = point(cart(P), color = 'blue', size = tamany)
aux = P
while (k > 0):
llistapunts.append(cart(aux))
if (k % 2 == 1):
frames.append(marc + list_plot(llistapunts, size = tamany, color = 'orange'))
frames.append(marc + list_plot(llistapunts, size = tamany, color = 'orange') + point(cart(aux), color = 'blue', size = tamanyextra) + puntPextra)
prev = aux
aux = E(aux)+E(P)
frames.append(marc + list_plot(llistapunts, size = tamany, color = 'orange') + point(cart(prev), color = 'blue', size = tamany) + puntP + point(cart(aux), color = 'green', size = tamanyextra))
llistapunts.append(cart(aux))
frames.append(marc + list_plot(llistapunts, size = tamany, color = 'orange'))
frames.append(marc + list_plot(llistapunts, size = tamany, color = 'orange') + point(cart(aux), color = 'blue', size = tamanyextra))
prev = aux
aux = E(aux)+E(aux)
frames.append(marc + list_plot(llistapunts, size = tamany, color = 'orange', gridlines = True) + point(cart(prev), color = 'blue', size = tamany) + point(cart(aux), color = 'green', size = tamanyextra))
k = k//2
animate(frames)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment