Path: blob/master/Elliptic-Curves/ellipticcurve.sage.py
1402 views
1# This file was *autogenerated* from the file ellipticcurve.sage2from sage.all_cmdline import * # import sage library34_sage_const_775807209463167910095539163959068826 = Integer(775807209463167910095539163959068826); _sage_const_775010084514487531788273912037060561 = Integer(775010084514487531788273912037060561); _sage_const_1 = Integer(1); _sage_const_771157329084582589666569152178346504 = Integer(771157329084582589666569152178346504); _sage_const_323141381196798033512190262227161667 = Integer(323141381196798033512190262227161667); _sage_const_869049850567812139357308211622374273 = Integer(869049850567812139357308211622374273); _sage_const_591153005086204165523829267245014771 = Integer(591153005086204165523829267245014771); _sage_const_238266381988261346751878607720968495 = Integer(238266381988261346751878607720968495); _sage_const_889774351128949770355298446172353873 = Integer(889774351128949770355298446172353873); _sage_const_12 = Integer(12); _sage_const_67890 = Integer(67890); _sage_const_341454032985370081366658659122300896 = Integer(341454032985370081366658659122300896); _sage_const_12345 = Integer(12345)5from sage.all import *67def _EllipticCurve(p, a, b):8E = EllipticCurve(GF(p), [a, b])9return E1011def _add(P, Q):12return P + Q1314def _scalar_mul(c, P):15return c*P1617def _testECC():18"""19Reference: https://ctftime.org/task/68602021Testing validity for single instance22"""23# Defining the Elliptic Curve24p = _sage_const_88977435112894977035529844617235387325a = _sage_const_1234526b = _sage_const_6789027E = _EllipticCurve(p, a, b)2829# Defining points on the Elliptic Curve30px, py = (_sage_const_238266381988261346751878607720968495 , _sage_const_591153005086204165523829267245014771 )31qx, qy = (_sage_const_341454032985370081366658659122300896 , _sage_const_775807209463167910095539163959068826 )32P = E((px, py))33Q = E((qx, qy))3435P_plus_Q = E((_sage_const_323141381196798033512190262227161667 , _sage_const_775010084514487531788273912037060561 ))36twelveP = E((_sage_const_771157329084582589666569152178346504 , _sage_const_869049850567812139357308211622374273 ))3738try:39assert _add(P, Q) == P_plus_Q40assert _scalar_mul(_sage_const_12 , P) == twelveP41except:42return -_sage_const_143return _sage_const_14445if _testECC() == _sage_const_1 :46print "[+] Test Passed!"47else:48print "[-] Test Failed!"49505152