n=p*q*r #n=85492663786275292159831603391083876175149354309327673008716627650718160585639723100793347534649628330416631255660901307533909900431413447524262332232659153047067908693481947121069070451562822417357656432171870951184673132554213690123308042697361969986360375060954702920656364144154145812838558365334172935931441424096270206140691814662318562696925767991937369782627908408239087358033165410020690152067715711112732252038588432896758405898709010342467882264362733 c=pow(flag,e,n) #e=0x1001 #c=75700883021669577739329316795450706204502635802310731477156998834710820770245219468703245302009998932067080383977560299708060476222089630209972629755965140317526034680452483360917378812244365884527186056341888615564335560765053550155758362271622330017433403027261127561225585912484777829588501213961110690451987625502701331485141639684356427316905122995759825241133872734362716041819819948645662803292418802204430874521342108413623635150475963121220095236776428 #so,what is the flag?
import sympy import random import gmpy2 from Crypto.Util.number import * defmyGetPrime(A,B): k=1 for i inrange(B+1,A): k=k*i%A x=gmpy2.invert(k,A) xB=-x%A return sympy.nextprime(xB)
from Crypto.Util.number import * from random import randint from gmpy2 import powmod import base64 import primefac defsame_n_attack(n,e1,e2,c1,c2): defegcd(a,b): x, lastX = 0, 1 y, lastY = 1, 0 while (b != 0): q = a // b a, b = b, a % b x, lastX = lastX - q * x, x y, lastY = lastY - q * y, y return (lastX, lastY) s = egcd(e1,e2) s1 = s[0] s2 = s[1] if s1 < 0: s1 = -s1 c1 = primefac.modinv(c1, n) if c1 < 0: c1 += n elif s2 < 0: s2 = -s2 c2 = primefac.modinv(c2, n) if c2 < 0: c2 += n m = (pow(c1, s1, n) * pow(c2, s2, n)) % n return m
import gmpy2 f1 = open(r"./HUB1", "r").readlines() f2 = open(r"./HUB2", "r").readlines() n=int(f1[0]) e1=int(f1[1]) e2=int(f2[1]) print(e1,e2) c='' gcd, s, t = gmpy2.gcdext(e1, e2) flag='' for i inrange(3,len(f2)): message1 = int(f1[i]) message2 = int(f2[i]) plain = same_n_attack(n,e1,e2,message1,message2) c=long_to_bytes(plain) flag+=str(c) print() flag = flag[2:-2].split('\\n') for i in flag: print(base64.b64decode(i).decode('utf-8'),end=' ')