/
get_curve_from_2p_and_prime.sage
35 lines (25 loc) · 1.09 KB
/
get_curve_from_2p_and_prime.sage
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from math import gcd
from Crypto.Util.number import *
from sage.all import *
P1 = (57965690875794075971012488152230149163602256508707811594337978733750915468806, 16746479600411735837174391941067872880449998685866235929656201743399769433149)
#P2 = (69936234690532721081726160313018549398162634031107454554647599731204812649342, 60370347819144291939385104514502372001122251366410414587034042305240897452453)
P2 = (68863793597568829791091117378551243306095213130450629884577755357985078854249, 57338665993204791888869144252570837621696803230095730917988989291398052731921)
p = 77842779395507334601861224827415108072619674595753802017004887970581678343527
def inverse_exists(x1,x2,p):
if (gcd((abs(x1-x2)), p) == 1):
return True
else:
return False
def obtain_a(P1,P2,p):
f = (P1[1]^2 - P2[1]^2) - (P1[0]^3 - P2[0]^3) % p
inv = inverse_mod((P1[0]-P2[0]), p)
a = f * inv % p
return a
def obtain_b(P,prime,a):
b = (P[1]^2 - P[0]^3 - a*P[0]) % prime
return b
if inverse_exists(P1[0],P2[0],p):
a = obtain_a(P1,P2,p)
b = obtain_b(P1,p,a)
print(a)
print(b)