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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
| from Crypto.Util.number import * from random import randint
class CB_curve: def __init__(self): self.p = 1141741939958844590498346884870015122543626602665954681008204697160652371664923 self.a = 727131475903635498678013730344448225340496007388151739960305539398192321065043 self.b = 840714623434321649308065401328602364673881568379142278640950034404861312007307
def add(self, P, Q): if P == -1: return Q (x1, y1) = P (x2, y2) = Q x3 = (x1+x2)*(1+self.a*y1*y2)*inverse((1+self.b*x1*x2) * (1-self.a*y1*y2), self.p) % self.p y3 = (y1+y2)*(1+self.b*x1*x2)*inverse((1-self.b*x1*x2) * (1+self.a*y1*y2), self.p) % self.p return (x3, y3)
def mul(self, x, P): Q = -1 while x > 0: if x & 1: Q = self.add(Q, P) P = self.add(P, P) x = x >> 1 return Q
ecc = CB_curve()
a = ecc.a b = ecc.b p = ecc.p
E = EllipticCurve(GF(p), [0, a+b, 0, a*b, 0]) x1 = -239643535167901657800210470774814532510308869595840873642845564328410464397042 % p
G = (586066762126624229327260483658353973556531595840920560414263113786807168248797, 66727759687879628160487324122999265926655929132333860726404158613654375336028)
y1 = 672929595307990944197873882889709005621738844588134711458648048321447534353147 P = (int(x1), int(y1)) G = E((b*G[0] - a*G[1]) * inverse_mod(G[1]-G[0], p) % p, (b-a)*inverse_mod(G[1]-G[0], p) % p) P = E((b*P[0] - a*P[1]) * inverse_mod(P[1]-P[0], p) % p, (b-a)*inverse_mod(P[1]-P[0], p) % p) order = G.order() order = 570870969979422295249173442435007561272085504844186092739816337605942962972880 primes = [3, 5, 16, 37, 271, 4297, 6983, 9679, 52631, 139571, 84666937, 558977989] logs = [] for fac in primes: t = int(order)//int(fac) log = discrete_log(t*P, t*G, operation='+') logs += [log] m = crt(logs, primes)
print(long_to_bytes(m))
|