Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ashutosh1206
GitHub Repository: ashutosh1206/crypton
Path: blob/master/Elliptic-Curves/ellipticcurve.sage.py
1402 views
1
2
# This file was *autogenerated* from the file ellipticcurve.sage
3
from sage.all_cmdline import * # import sage library
4
5
_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)
6
from sage.all import *
7
8
def _EllipticCurve(p, a, b):
9
E = EllipticCurve(GF(p), [a, b])
10
return E
11
12
def _add(P, Q):
13
return P + Q
14
15
def _scalar_mul(c, P):
16
return c*P
17
18
def _testECC():
19
"""
20
Reference: https://ctftime.org/task/6860
21
22
Testing validity for single instance
23
"""
24
# Defining the Elliptic Curve
25
p = _sage_const_889774351128949770355298446172353873
26
a = _sage_const_12345
27
b = _sage_const_67890
28
E = _EllipticCurve(p, a, b)
29
30
# Defining points on the Elliptic Curve
31
px, py = (_sage_const_238266381988261346751878607720968495 , _sage_const_591153005086204165523829267245014771 )
32
qx, qy = (_sage_const_341454032985370081366658659122300896 , _sage_const_775807209463167910095539163959068826 )
33
P = E((px, py))
34
Q = E((qx, qy))
35
36
P_plus_Q = E((_sage_const_323141381196798033512190262227161667 , _sage_const_775010084514487531788273912037060561 ))
37
twelveP = E((_sage_const_771157329084582589666569152178346504 , _sage_const_869049850567812139357308211622374273 ))
38
39
try:
40
assert _add(P, Q) == P_plus_Q
41
assert _scalar_mul(_sage_const_12 , P) == twelveP
42
except:
43
return -_sage_const_1
44
return _sage_const_1
45
46
if _testECC() == _sage_const_1 :
47
print "[+] Test Passed!"
48
else:
49
print "[-] Test Failed!"
50
51
52