# In [1]: n = 16175064088648626038689748434699435826247716579187475966092822028609536761351820951820375552440329596553448265674841223230257463367834546091974959931391707199002842774795702094681528411058318007858638798643010942408552063479863545047616823056802010158288409527763686086960916160949496083789920012040215745627854092010308869223489833074860062054019221397227691063339148923860987250696934050122115972982286012688955816234717242567815830341836031567275888691320640526306946586793028267588302696611724356566003447616419092371914903382944112125852939011729294400479171568234647164730191643282793224422368321464125847020067 c2 = [12053085469218650692076937068797478047679005585690696222988148891925249697123080938461512785257424651119325211991331622346111396522606463631848519999574540677285771456451798811902760319940781754940936484802949729402283626052963389539032949160905330315285409948932070460455535716223838438994608837585387741418172014634472651248450564788332400265295308803291229281839428962457585593065595521459963501453576128172245723315811398209056633738967993602668795794847967331946516181453804430961308142497659799416125763566765485760600358126127595222197324155943818136202233758771243043559460620477085689770403810190118485243364, 13878717704635179949812987989626985689079485417345626168168664941124566737996226347895779823781042724620099437593856913505609774929187720381745418166924229828643565384137488017127800518133460531729559408120123922005898834268035918798610962941606864727966963354615441094676621013036726097763695675723672289505864372820096404707522755617527884121630784469379311199256277022770033036782130954108210409787680433301426480762532000133464370267551845990395683108170721952672388388178378604502610341465223041534665133155077544973384500983410220955683686526835733853985930134970899200234404716865462481142496209914197674463932] g,h=c2 K=2**1600 M=Matrix(ZZ,[[1,0,0,g*h*K],[0,1,0,-(g+h)*K],[0,0,1,1*K],[0,0,0,K*n]]) print(M.LLL()[0])
# Out [1]: #(-1, -146436625375651639081292195233290471195543268962429, -21443685251408941546679213362069702254265669437874360093122983595763055555796655464630848682213580041, 0) #对应(1,m,m^2,w,0),差个了符号,无所谓
# In [2]: from Crypto.Util.number import * long_to_bytes(146436625375651639081292195233290471195543268962429)#直接复制上面第二个分量即可。 # Out [2]: #b'd2-bbe5-1420eaaa3b30}' #最终flag:flag{3e99c26b-efdd-4cd2-bbe5-1420eaaa3b30}
#reference: https://lazzzaro.github.io/2020/05/06/crypto-RSA/index.html from copy import deepcopy # https://www.iacr.org/archive/pkc2006/39580001/39580001.pdf # Author: ZM__________J, To1in N = 61857467041120006957454494977971762866359211220721592255304580940306873708357617802596067329984189345493420858543581027612648626678588277060222860337783377316655375278359169520243355170247177279595812282793212550819124960549824278287538977769728573023023364686725321548391592858202718446127851076431000427033 e = 22696852369762746127523066296087974245933137295782964284054040654103039210164173227291367914580709029582944005335464668969366909190396194570924426653294883884186299265660358589254391341147028477295482787041170991166896788171334992065199814524969470117229229967188623636764051681654720429531708441920158042161 alpha = log(e, N) beta = 0.3 delta = 0.1 P.<x,y,z>=PolynomialRing(ZZ)
X = ceil(2 * N^(alpha + beta + delta - 1)) Y = ceil(2 * N^beta) Z = ceil(2 * N^(1 - beta))
deff(x,y): return x*(N-y)+N deftrans(f): my_tuples = f.exponents(as_ETuples=False) g = 0 for my_tuple in my_tuples: exponent = list(my_tuple) mon = x ^ exponent[0] * y ^ exponent[1] * z ^ exponent[2] tmp = f.monomial_coefficient(mon)
my_minus = min(exponent[1], exponent[2]) exponent[1] -= my_minus exponent[2] -= my_minus tmp *= N^my_minus tmp *= x ^ exponent[0] * y ^ exponent[1] * z ^ exponent[2]
g += tmp return g
m = 5# need to be adjusted according to different situations tau = ((1 - beta)^2 - delta) / (2 * beta * (1 - beta)) sigma = (1 - beta - delta) / (2 * (1 - beta))
print(sigma * m) print(tau * m)
s = ceil(sigma * m) t = ceil(tau * m) my_polynomials = [] for i inrange(m+1): for j inrange(m-i+1): g_ij = trans(e^(m-i) * x^j * z^s * f(x, y)^i) my_polynomials.append(g_ij)
for i inrange(m+1): for j inrange(1, t+1): h_ij = trans(e^(m-i) * y^j * z^s * f(x, y)^i) my_polynomials.append(h_ij)
# construct partial order whilelen(my_polynomials) > 0: for i inrange(len(my_polynomials)): f = my_polynomials[i] current_monomial_set = set(x^tx * y^ty * z^tz for tx, ty, tz in f.exponents(as_ETuples=False)) delta_set = current_monomial_set - known_set iflen(delta_set) == 1: new_monomial = list(delta_set)[0] my_monomials.append(new_monomial) known_set |= current_monomial_set new_polynomials.append(f) my_polynomials.pop(i) break else: raise Exception('GG')
my_polynomials = deepcopy(new_polynomials)
nrows = len(my_polynomials) ncols = len(my_monomials) L = [[0for j inrange(ncols)] for i inrange(nrows)]
for i inrange(nrows): g_scale = my_polynomials[i](X * x, Y * y, Z * z) for j inrange(ncols): L[i][j] = g_scale.monomial_coefficient(my_monomials[j])
# remove N^j for i inrange(nrows): Lii = L[i][i] N_Power = 1 while (Lii % N == 0): N_Power *= N Lii //= N L[i][i] = Lii for j inrange(ncols): if (j != i): L[i][j] = (L[i][j] * inverse_mod(N_Power, e^m))
L = Matrix(ZZ, L) nrows = L.nrows()
L = L.LLL() # Recover poly reduced_polynomials = [] for i inrange(nrows): g_l = 0 for j inrange(ncols): g_l += L[i][j] // my_monomials[j](X, Y, Z) * my_monomials[j] reduced_polynomials.append(g_l)
my_ideal_list= [y * z - N] + reduced_polynomials
# Variety my_ideal_list = [Hi.change_ring(QQ) for Hi in my_ideal_list] for i inrange(len(my_ideal_list),3,-1): print(i) V = Ideal(my_ideal_list[:i]).variety(ring=ZZ) print(V) """ OUTPUT: 2.14285714285714 4.64285714285714 52 [] 51 [] 50 [] 49 [] 48 [] 47 [] 46 [] 45 [] 44 [] 43 [] 42 [] 41 [{z: 426614979768518060635433317149972303610396098751783498586225631589479798053751568080185868568717967344782297587209012869059719479952019313461850777653567018452929932659204669967695196434044149034271037885062392902287, y: 144996003362760405215910388196517232449311004246441924325936847006315296003811348342536838359, x: 66838488369949543369599279980954380920457752396291961341704448955532596917094831390389571041281062121515985150418852560085}] 40 [{z: 426614979768518060635433317149972303610396098751783498586225631589479798053751568080185868568717967344782297587209012869059719479952019313461850777653567018452929932659204669967695196434044149034271037885062392902287, y: 144996003362760405215910388196517232449311004246441924325936847006315296003811348342536838359, x: 66838488369949543369599279980954380920457752396291961341704448955532596917094831390389571041281062121515985150418852560085}] """
defsome_calc(size, depth): defsums_calc(base, degree): result = 0 for i inrange(degree): temp = temp_calc(base ** i) result += base ** i + temp // temp_calc(base**(i + 1)) return result
n = 659401821142664131364043958430747314465977448744532421905138184036743766362324320051729418680079590835903781525157600055608268591994754328563246418114269690475272262915661210669701969695314157602927462228079044905276064391615467601628466982949165371933147600418057089432876120807721483665788557812323607370950442342057254926375842684430119320789097029996211564275310819486004520088130146630452262340185192110066151930586956190499953220051855668474863659201165952231016814569364299000130323859609047687714260776467149437031397019411599103716200258382231589757031469168245396061619327867355414287059363691024984066070128364157490336808211223714816668548049472199794493895870662970541167490686648385211854469386812214775829776376273299648505880034651930322294605482489225723014758138525637864689594748771025870209444029669477294995691067669374491852721622469656239730320092112222948718027850386898461208936333788173263904607181823233002355650353116486156927403178510412091666951574340730799316032588099237 c = 455042981325030540026829365098432813829591020497037525707600104817313008442900331256387443469027825344761381076471749826547710666806180999603254398722965179851898391700090501419875562919365894255855734276825027850795202733875071307773598881254863911398285400038957998385685292965812925607278232164067624548120378758414574370042945538632864154772437639053907149514588502689277630450575630168099810584842881257614115970132960679023265157277718654731105815060916800751033956715430930381384344469220951638102432198422350425390757155267143393385221465041749156153517556389417033187856017198907366720281408810250981776112815100319814215140919133440637395953567624057248002125277569474190364142291136361144552953540727462623677375371327473687508344483184466522697912317252462246054471196345909304668083637177166153036111122244170846815657389873986264187766636830907458940128844256504176917204131708083105093700023335939233711693409336968008112511482237441198116493965744903995545941700742865846469036763734618 e = 0x10001
from Crypto.Util.number import * n = c = e = k = 5
R = Zmod(n)["x"] whileTrue: Q = R.quo(R.random_element(k)) pp = gcd(ZZ(list(Q.random_element() ^ n)[1]), n) if pp != 1: qq = sum([pp**i for i inrange(k)]) rr = n // (pp * qq) assert n == pp * qq * rr break phi = (pp - 1) * (qq - 1) * (rr - 1) d = pow(e, -1, phi) m = pow(c, d, n) print(long_to_bytes(int(m))) #b'flag{som3thing_1nter3sting_1n_su5}'
4o02 Proof
当然直接把原题搬过来肯定是不太好的,看看怎么证明的?
Pick a random polynomial $f(x)=x^3+ax^2+bx+c$, and pick a random element a in $R=\mathbb Z_n[x]/f(x)$ . If $f(x)$ is irreducible in $\mathbb F_p[x]$ then the filed $\mathbb K=\mathbb F_p[x]= \mathbb F_p[x]/f(x)=\mathbb F_{p^3}$ will be a field with order $p^3−1=(p−1)(p^2+p+1)$.
We raise a to the power of $n=pqr=p(p^2+p+1)r$ then an would probably be of order $p−1$, which implies it will be in the form of $u+0x+0x^2$ in $\mathbb K$. This means we can take the degree $1$ or $2$ coefficient of an in $R$ and gcd it with $n$ to get $p$, then we can fully factor $n$ to decrypt the flag.
This is basically the same idea as Pollard’s $p-1$ or Williams’ $p+1$ factorization algorithm, but we are doing it in a field with higher degree.
''' S = [624073892368439332713131144655355187273652775732037030273908973687487472640419, 1129513550732743550887354593625951854836036688324123410864182971141396110133306, 1117643028354341949186759218964558582164677605237787761003042032239935547551873, 151619055620013230556169740951169935393567570823439146992800622058967940011364, 596106506159944398847755500086869373163910176213091804211992440336880292610397, 685472210701608040945173323626153641749419080165879222271110177606156013942182] V = [100024809269721744282017864103544473542698741247649693420201028956644193231147, 85493218764912449360009112267171851264674952927507787108286827385372626006804, 75451455656190167222034904545925816909383290106210237096763781707294423744719, 1864420400658866895837249178680154965580281261003086054650703872439476331244, 111069754111223622246512532174936637994215526100226395068812327641951277359169, 88031405587803201423744918486788030404029698214504194443110805396831023823738] n = 1497114501625523578039715607844306226528709444454126120151416887663514076507099 '''
rickroll.txt
1 2 3 4 5 6 7 8 9
Never gonna give you up Never gonna let you down Never gonna run around and desert you Never gonna make you cry Never gonna say goodbye Never gonna tell a lie and hurt you --A mysterious singer who does not want to be named.
from Crypto.Util.number import * from Crypto.Util.Padding import pad import os from hashlib import * from random import * defbytexor(b1,b2): if(len(b1)<len(b2)): b1,b2=b2,b1 lenb1,lenb2=len(b1),len(b2) bs=[0]*lenb1 for i inrange(lenb1): bs[i]=b1[i]^^b2[i%lenb2] returnbytes(bs) Msg=[ b'Never gonna give you up', b'Never gonna let you down', b'Never gonna run around and desert you', b'Never gonna make you cry', b'Never gonna say goodbye', b'Never gonna tell a lie and hurt you'] S = [624073892368439332713131144655355187273652775732037030273908973687487472640419, 1129513550732743550887354593625951854836036688324123410864182971141396110133306, 1117643028354341949186759218964558582164677605237787761003042032239935547551873, 151619055620013230556169740951169935393567570823439146992800622058967940011364, 596106506159944398847755500086869373163910176213091804211992440336880292610397, 685472210701608040945173323626153641749419080165879222271110177606156013942182] V = [100024809269721744282017864103544473542698741247649693420201028956644193231147, 85493218764912449360009112267171851264674952927507787108286827385372626006804, 75451455656190167222034904545925816909383290106210237096763781707294423744719, 1864420400658866895837249178680154965580281261003086054650703872439476331244, 111069754111223622246512532174936637994215526100226395068812327641951277359169, 88031405587803201423744918486788030404029698214504194443110805396831023823738] n = 1497114501625523578039715607844306226528709444454126120151416887663514076507099 q=n//2 detAx04=(V[0]-V[4])%q detBx04=(S[0]-S[4])%q detAx13=(V[1]-V[3])%q detBx13=(S[1]-S[3])%q M=[ [1,0,0,(2**96*detAx13)%q], [0,1,0,(-2**96*detAx04%q)], [0,0,1,(detBx04*detAx13-detAx04*detBx13)%q], [0,0,0,q] ] M=Matrix(ZZ,M) M=M*diagonal_matrix(ZZ,[2**8,1,2**96,2**96]) MLLL=M.LLL() for v in MLLL: if(v[2]==2**96): break