Skip to content

Instantly share code, notes, and snippets.

@Jun-Wang-2018
Last active March 3, 2019 06:18
Show Gist options
  • Save Jun-Wang-2018/6527e218ccff82996763e01b8184e923 to your computer and use it in GitHub Desktop.
Save Jun-Wang-2018/6527e218ccff82996763e01b8184e923 to your computer and use it in GitHub Desktop.
Double a point on a elliptic curve
# An example of predfined parameters
a = 1; b = 1
P = 23
x1 = 0; y1 = 1
G = (x1,y1)
# Function
def ECdouble(G,a,b,P): # G = (x1,y1) where x1,y1 are integers.
lambda_mod = (3*G[0]** 2 + a)% P * modular_inverse(2*G[1],P)
x3 = (lambda_mod * lambda_mod - G[0] - G[0]) % P
y3 = (lambda_mod * (G[0]-x3)-G[1]) % P
return (x3,y3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment