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 92 93 94 95 96 97
| from Crypto.Util.number import * from gmpy2 import * from secrets import flag import random
def add(P,Q): (x1,y1)=P (x2,y2)=Q
x3=(x1+x2)*(1+y1*y2)*invert((1+x1*x2)*(1-y1*y2),p)%p y3=(y1+y2)*(1+x1*x2)*invert((1-x1*x2)*(1+y1*y2),p)%p
return (x3,y3)
def mul(e,P): Q=(0,0) e=e%p while e: if e&1: Q=add(Q,P) P=add(P,P) e>>=1 return Q
def Legendre(a,p): return (pow((a%p+p)%p,(p-1)//2,p))%p
def get_ts(p): p=p-1 count=0 while p%2==0: count+=1 p=p//2 return count,p
def get_nonre(p): a=random.randint(1,p) while Legendre(a,p)==1: a=random.randint(1,p) return a
def amm2(a,p): t,s=get_ts(p) ta=pow(get_nonre(p),s,p) tb=pow(a,s,p) h=1 for i in range(1,t): d=pow(tb,2**t-1-i,p) if d==1: k=0 else: k=1 tb=(tb*pow(ta,2*k,p))%p h=(h*pow(ta,k,p))%p ta=pow(ta,2,p) return h*pow(a,(s+1)//2,p)%p
def solve(a,b,c,p): tmpa=1 tmpb=b*inverse(a,p)%p tmpc=c*inverse(a,p)%p assert Legendre(tmpb**2*inverse(4,p)-tmpc,p)==1 res1=(amm2(tmpb**2*inverse(4,p)-tmpc,p)-tmpb*inverse(2,p))%p res2=(-amm2(tmpb**2*inverse(4,p)-tmpc,p)-tmpb*inverse(2,p))%p return (res1,res2)
def lift(x,a,b,p): tmp=b*(x**2-1)*inverse(a*x,p)%p return solve(1,-tmp,-1,p)[0]
p=9410547699903726871336507117271550134683191140146415131394654141737636910570480327296351841515571767317596027931492843621727002889086193529096531342265353 a=54733430689690725746438325219044741824500093621550218736194675295708808435509 b=75237024593957256761258687646797952793573177095902495908321724558796076392871 x=bytes_to_long(flag)
while True: try: y=lift(x,a,b,p) break except: x+=1 continue
assert a*x*(y**2-1)%p == b*y*(x**2-1)%p
P=(x,y) e=65537
eP=mul(e,P) print(f"P = {P}") print(f"eP = {eP}")
''' P = (56006392793427940134514899557008545913996191831278248640996846111183757392968770895731003245209281149, 5533217632352976155681815016236825302418119286774481415122941272968513081846849158651480192550482691343283818244963282636939305751909505213138032238524899) eP = (mpz(8694229840573103722999959579565187489450818138005222030156495740841851804943200684116883831426548909867463656993852596745698999492932194245562062558787005), mpz(9279986963919197374405152604360936066932975197577643570458423456304679111057526702737279809805694360981565554506626018364382736924914907001214909905449002)) '''
|