Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ashutosh1206
GitHub Repository: ashutosh1206/crypton
Path: blob/master/Elliptic-Curves/ellipticcurve.sage
1402 views
1
from sage.all import *
2
3
def _EllipticCurve(p, a, b):
4
E = EllipticCurve(GF(p), [a, b])
5
return E
6
7
def _add(P, Q):
8
return P + Q
9
10
def _scalar_mul(c, P):
11
return c*P
12
13
def _testECC():
14
"""
15
Reference: https://ctftime.org/task/6860
16
17
Testing validity for single instance
18
"""
19
# Defining the Elliptic Curve
20
p = 889774351128949770355298446172353873
21
a = 12345
22
b = 67890
23
E = _EllipticCurve(p, a, b)
24
25
# Defining points on the Elliptic Curve
26
px, py = (238266381988261346751878607720968495, 591153005086204165523829267245014771)
27
qx, qy = (341454032985370081366658659122300896, 775807209463167910095539163959068826)
28
P = E((px, py))
29
Q = E((qx, qy))
30
31
P_plus_Q = E((323141381196798033512190262227161667, 775010084514487531788273912037060561))
32
twelveP = E((771157329084582589666569152178346504, 869049850567812139357308211622374273))
33
34
try:
35
assert _add(P, Q) == P_plus_Q
36
assert _scalar_mul(12, P) == twelveP
37
except:
38
return -1
39
return 1
40
41
if _testECC() == 1:
42
print "[+] Test Passed!"
43
else:
44
print "[-] Test Failed!"
45
46