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/9ef685a7001b3ccd10b55690db82dff0 to your computer and use it in GitHub Desktop.
Save Jun-Wang-2018/9ef685a7001b3ccd10b55690db82dff0 to your computer and use it in GitHub Desktop.
Add two points on a elliptic curve
# Predfined parameters (x1,y1,x2,y2 are integers)
A = (x1,y1); B = (x2,y2)
# Function
def ECadd(A,B):
lambda_mod = (B[1]-A[1])% P * modular_inverse(B[0]-A[0], P)
x3 = (lambda_mod * lambda_mod - A[0] - B[0]) % P
y3 = (lambda_mod * (A[0] - x3) - A[1]) % P
return (x3,y3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment