Path: blob/master/Elliptic-Curves/ellipticcurve.sage
1402 views
from sage.all import *12def _EllipticCurve(p, a, b):3E = EllipticCurve(GF(p), [a, b])4return E56def _add(P, Q):7return P + Q89def _scalar_mul(c, P):10return c*P1112def _testECC():13"""14Reference: https://ctftime.org/task/68601516Testing validity for single instance17"""18# Defining the Elliptic Curve19p = 88977435112894977035529844617235387320a = 1234521b = 6789022E = _EllipticCurve(p, a, b)2324# Defining points on the Elliptic Curve25px, py = (238266381988261346751878607720968495, 591153005086204165523829267245014771)26qx, qy = (341454032985370081366658659122300896, 775807209463167910095539163959068826)27P = E((px, py))28Q = E((qx, qy))2930P_plus_Q = E((323141381196798033512190262227161667, 775010084514487531788273912037060561))31twelveP = E((771157329084582589666569152178346504, 869049850567812139357308211622374273))3233try:34assert _add(P, Q) == P_plus_Q35assert _scalar_mul(12, P) == twelveP36except:37return -138return 13940if _testECC() == 1:41print "[+] Test Passed!"42else:43print "[-] Test Failed!"444546