Skip to content

Instantly share code, notes, and snippets.

@Jun-Wang-2018
Last active March 3, 2019 06:24
Show Gist options
  • Save Jun-Wang-2018/013fa159d2ee9dc0ea531d3e6e7a9912 to your computer and use it in GitHub Desktop.
Save Jun-Wang-2018/013fa159d2ee9dc0ea531d3e6e7a9912 to your computer and use it in GitHub Desktop.
Multiplicate a point on a elliptic curve
# a,b define a elliptic curve. y**2 = a*x**3 + b*x
# G(x1,y1) is the base point.
# P is a large prime. N is the order of the base point and usually equals to the order of the curve.
def ECMultiplication(G,a,b,P,N,privateKey):
#if privateKey < 1 or privateKey >= N: raise Exception("ECMultiplication(G,a,b,P,privateKey), privateKey should >0 and <N.")
n_binary = str(bin(privateKey))[2:]
D = G
for i in range (1, len(n_binary)):
D = ECdouble(D,a,b,P)
if n_binary[i] == "1":
D = ECadd(D, G)
return D
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment