import os import matplotlib.pyplot as plt data=[] withopen('hiddata.txt',"r") as f: for line in f.readlines(): data.append(line) X = [] Y = [] for line in data: x0=int(line[4:6],16) x1=int(line[6:8],16) x=x0+x1*256 y0=int(line[8:10],16) y1=int(line[10:12],16) y=y0+y1*256 X.append(x) Y.append(-y) fig = plt.figure() ax1 = fig.add_subplot(111) ax1.set_title("result") ax1.scatter(X, Y, c='b', marker='o') plt.show()
from sage.allimport * from Crypto.Util.number import getPrime, bytes_to_long from random import randint from itertools import product, combinations n =10762816985859495139869192967586986169700585407650401758492914432007691215829829791170341055156952976765180258893167491520857418187717684546804091210840024146052291097940830614742073364552838290223328178129141450654974155663740167060363586046667418448000998787456156206763022665332848878718353207304752459866785987037244104966604168107428925002453961599326527075890562706405965932261029119740876890925151892381057306445871753182344654732310415856215026583156200205190290229513783502698870703593936084079889610093661632981253566737244298490483887491349685327054110713416608442026862452848911878315454050801737258113439 c =8447423691845267507910623881220381551666985692061130076228863364484545883136565538153853576456124232843440600389531458361591643000579120508101213567369995084232851488318213585166763995128971205060742692924173515480605390369108788114163397502997675308466114417550035850225404358223296655286051772334268473129000095354558509683438282602907669640723660576086897314122077227840018348574919569323961412521005657567879672836500813700075919902705930777791052105528663343979204155473143542923352804010273593743826083253263605472374027833649945128024719518687833938452374975314769405521418020888003402906733694105525873475248 hints =[1037185901048299733994080148617255395054343048856247908410601987778479809878530408488320575174117338778636437390189707472850545495340030261432470823966833296599326227471363743571435638488350843501335163114522221236295887873384511904404076136719828753484908833522690485308801343692672087896916151728355339557063865979845334871596911380941183991996355328789626661832721727696996294542137065146082233136253,846732177805839592702453549495036743295384625187602625155533672143689218095451041579929817175558384214705957953439776505091441694232911111216302515231684660931114920885206001996415471667166302864276782382471749478878838743894218008585118570123564743506751263851346701898521514512630773037841739309871594639329517489797555801372814456505858967177535379362107863024397586339230559713504606369217391562005,1217849239241871953321322081958369125171815220222141431376710417230239975203684179024894356985970928925706068277775190791530588613770873433292421516394141880830700610067858856573183833274026726718793895096348188237821645080587133237246160317789656442199700812194023448514540614924352568135486220217732774487120710678057024335377334874015695483740444589213501325972313562358601186396370236713889278627191] h1, h2, h3 = hints L = matrix(hints).T.augment(matrix.identity(3)) L[:, 0] *= n L = L.LLL() for v in L: print(v) print([x.bit_length() for x in v]) _, t, u, v = L[0] a1s, a2s, a3s, b1s, b2s, b3s = QQ["a1,a2,a3,b1,b2,b3"].gens() for sign in product((-1, 1), repeat=3): I = ideal( [ a3s * b2s - a2s * b3s + sign[0] * t, a3s * b1s - a1s * b3s + sign[1] * u, a2s * b1s - a1s * b2s + sign[2] * v, ] ) if I.dimension() != -1: print(sign) print("dim", I.dimension())
defstep2(f): print("=" * 40) print(f) L = matrix(f.coefficients()).T.augment(matrix.identity(3)) L[:, 0] *= n L = L.LLL() print(L[0]) print(L[1]) v1 = L[0] v2 = L[1] xs = [] for c1, c2 in product((-2, -1, 0, 1, 2), repeat=2): v = c1 * v1 + c2 * v2 _, x1, x2, x3 = v ifall([0 <= x <= 2**312for x in (x1, x2, x3)]): xs.append((x1, x2, x3)) for g1, g2 in combinations(xs, 2): a1r, a2r, a3r = g1 b1r, b2r, b3r = g2 q = gcd(a2r * h1 - a1r * h2, n) if1 < q < n: p = n // q e = 0x10001 d = inverse_mod(e, (p - 1) * (q - 1)) m = pow(c, d, n) flag = int(m).to_bytes(1024, "big").strip(b"\x00") print(flag) exit() step2(I.groebner_basis()[1])