Last active
March 3, 2019 06:24
-
-
Save Jun-Wang-2018/013fa159d2ee9dc0ea531d3e6e7a9912 to your computer and use it in GitHub Desktop.
Multiplicate a point on a elliptic curve
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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