from Crypto.Util.number import * from hashlib import md5
c = 2420624631315473673388732074340410215657378096737020976722603529598864338532404224879219059105950005655100728361198499550862405660043591919681568611707967
p=81911394167511996830305370213894554209992159667974516868378702592733037962549 q=59689394622751323780317475130818337618980301243859922297121750335804594909859 n=p*q phi=pow(p,6)*(p-1)*(q-1) d=inverse(0x10001,phi) msg=long_to_bytes(pow(c,d,n)) flag = 'd3ctf{'+md5(msg).hexdigest()+'}' print(flag)
defsmall_roots(f, bounds, m=1, d=None): ifnot d: d = f.degree()
R = f.base_ring() N = R.cardinality()
f /= f.coefficients().pop(0) f = f.change_ring(ZZ)
G = Sequence([], f.parent()) for i inrange(m+1): base = N ^ (m-i) * f ^ i for shifts in itertools.product(range(d), repeat=f.nvariables()): g = base * prod(map(power, f.variables(), shifts)) G.append(g)
factors = [monomial(*bounds) for monomial in monomials] for i, factor inenumerate(factors): B.rescale_col(i, factor)
B = B.dense_matrix().LLL()
B = B.change_ring(QQ) for i, factor inenumerate(factors): B.rescale_col(i, 1/factor)
H = Sequence([], f.parent().change_ring(QQ)) for h infilter(None, B*monomials): H.append(h) I = H.ideal() if I.dimension() == -1: H.pop() elif I.dimension() == 0: roots = [] for root in I.variety(ring=ZZ): root = tuple(R(root[var]) for var in f.variables()) roots.append(root) return roots
return []
d = {'a': 3591518680290719943596137190796366296374484536382380061852237064647969442581391967815457547858969187198898670115651116598727939742165753798804458359397101, 'c': 6996824752943994631802515921125382520044917095172009220000813718617441355767447428067985103926211738826304567400243131010272198095205381950589038817395833, 'p': 7386537185240346459857715381835501419533088465984777861268951891482072249822526223542514664598394978163933836402581547418821954407062640385756448408431347} a, c, p = d['a'], d['c'], d['p'] h = [67523583999102391286646648674827012089888650576715333147417362919706349137337570430286202361838682309142789833, 70007105679729967877791601360700732661124470473944792680253826569739619391572400148455527621676313801799318422] enc = 6176615302812247165125832378994890837952704874849571780971393318502417187945089718911116370840334873574762045429920150244413817389304969294624001945527125 P. < x, y > = PolynomialRing(GF(p)) f = a*(2 ^ 146*h[0]+x) ^ 2+c-(2 ^ 146*h[1]+y) l = small_roots(f, (2 ^ 146, 2 ^ 146), m=4, d=4) assertlen(l) > 0 l1, l2 = l[0] s1, s2 = 2 ^ 146*h[0]+l1, 2 ^ 146*h[1]+l2 P. < z >= PolynomialRing(GF(p)) f = a*z ^ 2+c-s1 l = [int(i[0]) for i in f.roots()] for i in l: flag = int.from_bytes(hashlib.sha512(b'%d' % (i)).digest(), 'big') ^ ^enc flag = bytes.fromhex(hex(flag)[2:]) ifb'd3ctf'in flag: print(flag)