江苏移动“建材赋能”线下个人决赛crypto三道0解题
1089607995167011 发表于 江苏 CTF 137浏览 · 2024-11-30 06:12

ez_Eulers_theorem

from Crypto.Util.number import getStrongPrime, bytes_to_long
from gmpy2 import powmod
flag=b'flag{uaioijdioaiodjwioiajdi}'

p = getStrongPrime(512)
q = getStrongPrime(512)
r = getStrongPrime(512) * p
n = p * q * r
t1 = 2334 + r - r // p - p  
t2 = 23334 + r - r // p - p      
test_1 = powmod(q, t1, r)    
test_2 = powmod(q, t2, r)                                            

e = 65537
m = bytes_to_long(flag)
c = powmod(m, e, n)
print(f"n = {n}")
print(f"c = {c}")
print(f"e = {e}")
print(f"r = {r}")
print(f"test_1 = {test_1}")
print(f"test_2 = {test_2}")

"""
n = 19394374939804636077298787696999145651388601917322114895642838853953381808240702298158075667836933844491914300462200498201232502597820471480278104873709079654383571733982600793391645736041575554416761411190577666894319909094358212628600451699873050386633961355953081164797613802471503835972928156332452586946123449475018268744050878129654089828539569290163248669910546474863971193248913060301042961297573273735567035638484842640891102000757796883117449143733645075205787306969545619475615329292516687937499869527048405181860848871040143454231725384444493671341489194232832604336747339981987968136805889988687471700689
c = 3445029509586789808191705086645892423344577895037990571917352198546103689956715444033789264619614928374173476257167068005615154238272256059206608521783259242336753735756270112683064185174154799787961620809472112672118869269531775498552913966749136960082148806701372215067784028138932161876481489483873874799577724564723536348878312087744205685152618944049898188467560333943868310819003549830041266285452470975843082633880273304056420983351380067924031473031902543251747872634679470807321088893876373614041197021272507490311894156474653766409806436771639703723056721686546437267761800664890347807938625483929875463817
e = 65537
r = 137186922017951798551013401031704441055292816273244383207330822587665397547633114179564214318161419547692944354372913721036795205992346900855775319896575433470493561754043711065187018521093256306861110861619139917879019066158769928044089694954100132993743545321108599987390965031813714252751340253063380122781  
test_1 = 10484222645942880569836346075211281500874316946773201245651921797050891795748018447890023984042009352443993529052624578259137283707622203132903778636427100673857236327880267380370130055336876593685230110403102135481150897000578831309789840644914684399062683490015265131603393965109484777590220067155254662724
test_2 = 46456546765497070754887354077605248455173445868539256339074654174920046820647882073337928470491562197950314697051806785137505130712091646483422595416843622895712210098782991926220638941734115040651715763329324337370957581802656073016916306620765962524561139196288970336270965816673108758049003178870509619277
"""

法一:欧拉定理

t1 = 2334 + r - r // p - p   
t2 = 23334 + r - r // p - p  

#r=tp

#p(t-1)-t+2334=pt-p-t+2334=t(p-1)-p+2334=phi(r)+2333

#p(t-1)-t+23334==t(p-1)-p+23334=phi(r)+23333  

pow(q,phi(r),r)==1,
test_1 = powmod(q, t1, r)       

phi(r)=(t-1)*(p-1)=tp-p-t+1          

pow(q,phi(r),r)*pow(q,2333,r)=pow(q,2333,r)
test_2 = powmod(q, t2, r)                                                

#pow(q,23333,r)

#pow(q,23333,r)

最后得到test1=pow(q,23333,r)

test2=pow(q,23333,r)

法二

n//r和r有公因子p

from Crypto.Util.number import *
from gmpy2 import *

n = 19394374939804636077298787696999145651388601917322114895642838853953381808240702298158075667836933844491914300462200498201232502597820471480278104873709079654383571733982600793391645736041575554416761411190577666894319909094358212628600451699873050386633961355953081164797613802471503835972928156332452586946123449475018268744050878129654089828539569290163248669910546474863971193248913060301042961297573273735567035638484842640891102000757796883117449143733645075205787306969545619475615329292516687937499869527048405181860848871040143454231725384444493671341489194232832604336747339981987968136805889988687471700689
c = 3445029509586789808191705086645892423344577895037990571917352198546103689956715444033789264619614928374173476257167068005615154238272256059206608521783259242336753735756270112683064185174154799787961620809472112672118869269531775498552913966749136960082148806701372215067784028138932161876481489483873874799577724564723536348878312087744205685152618944049898188467560333943868310819003549830041266285452470975843082633880273304056420983351380067924031473031902543251747872634679470807321088893876373614041197021272507490311894156474653766409806436771639703723056721686546437267761800664890347807938625483929875463817
e = 65537
r = 137186922017951798551013401031704441055292816273244383207330822587665397547633114179564214318161419547692944354372913721036795205992346900855775319896575433470493561754043711065187018521093256306861110861619139917879019066158769928044089694954100132993743545321108599987390965031813714252751340253063380122781
test_1 = 10484222645942880569836346075211281500874316946773201245651921797050891795748018447890023984042009352443993529052624578259137283707622203132903778636427100673857236327880267380370130055336876593685230110403102135481150897000578831309789840644914684399062683490015265131603393965109484777590220067155254662724
test_2 = 46456546765497070754887354077605248455173445868539256339074654174920046820647882073337928470491562197950314697051806785137505130712091646483422595416843622895712210098782991926220638941734115040651715763329324337370957581802656073016916306620765962524561139196288970336270965816673108758049003178870509619277

nn=n//r
p=gcd(nn,r)
q=nn//p
phi=(p-1)*p*(q-1)*(r//p-1)
d=invert(e,phi)
m=pow(c,d,n)
print(long_to_bytes(m))#flag{469c3244-1a40-4372-9aae-bca0aa75c583}

EZcopper

本题给了一个pem文件

用离线赛博厨子解pem to hex

30820815
 02820380
  n=067f0aa4e974a63a1ffe8d5c23e5d3c431653ae41cc746f305f62a9f193f22486cb7ef1b275634818f46d0752a5139e19918271fa0d7d27bc660d2b72414d08ea52c8837f949c7baecc3029ba31727ef3bf120d9926c02d7412f187e98dc56dd07b987d2cc191ad56164a144f28b2f70a15d105588a4f27fbb2891fc527bd6890a5f795b5c48476a6bf9dfb67b7e1ebc7b1b086cd28b58c68955bfdf44ecce11ffacdf654551b159b7832040cc28ee8ebea48f8672d53e3de88fcfbb5fb276b503880dd34d5993335ddf8ccb96c1b4d79f502d72104765ad9c2b1858a17af3d5be44fa3cbf4b8eeb942aa3942a3871d2c65ac70289123fc2e9f9b25cbfcbd7841096060fa504c3a07b591493c64c88d0bb45285a85b5f7d59db98faa00c2cd3fbb63da599205f1cab0df52cf7b431a0ee4a7e35696546ce9d03ef595ecee92d2142c92e97d2744939703455b4c70dec27c321ec6b83c029622e83a9e0d55d0b258d95d4e61291865dda76dc619fce9577990429c6e77e9d40781e3b2f449701b83e8b0c6c66eb380f96473e5d422efee8b2b0e88b716b00a79c9d514ca3ad9d2dee526609ff9541732a4198d11b9dbfbb2e55c24d80ea522d0786e3355f23606a5d38a72de4eefc8b6bfc482248a2862cb69d8e0e3d316597da9d80828be85054faf15fc369caacafb815c6973c171940683d56a1a1967b09b7ffa3fbe5b2e08699759d84d71603f516447696bb27322a69f39f6ca253e00dc9555d5f97328070c467f3663cc489aad130f28c42f35bf88c571920ab92acb8f75d03e35a75103c5bd96f061c96bd02af6e1d191b0dd164bc721377003edbf5d3ef65a5e9046385356b521623bee37f164850a0a7afb0ed4e7e8bd9afe1298f7d532bc9ad941812d332aece75d1cccb1ff69fd42b31f248ae579d9e0d6a14b0546e784ba940e32bd01c395df8ff4584040462b5479fa07336d503dc332e70fc06d9463297fc042b623d56f87efaa525a9b580e314d90d1211893ed407a26508deaa0a13c9ee8c902b9e1c3a02fe9a51452c02ee7bdcc85c0eff63891e24703bd265d9c9dbf456e2af9409538bce0fecc7ebab20266aaab06c766c3ea6cda9cb9ba5e1d024b7dc3d73e76f6a333197bad87c4fb34d565a0014aac72825e41adcfeadadc87acef40ad84b7c55691abad561be0550ea0a988470c427432acb8feb2b9d2d2598fb2089bb91bbd9cb199e892d36164d8bf3ecd54576a97134047a12da84207485bb4e5
 0203
  010001
 028203
  800400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
 02818100
  ph=8063d0a21876e5ce1e2101c20015529066ed9976882d1002a29efe0f2fdfcc2743fc9a4b5b651cc97108699eca2fb1f3d93175bae343e7c92e4a41c72d05e57019400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
 02818100
  qh=e4f0fe49f9ae1492c097a0a988fa71876625fe4fce05b0204f1fdf43ec64b4dac699d28e166efdfc7562d19e58c3493d9100365cf2840b46c0f6ee8d964807170ff2c13c4eb8012ecab37862a3900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

给了pq的高位,用二元copper解即可

import itertools
from Crypto.Util.number import *

def small_roots(f, bounds, m=1, d=None):
    if not 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 in range(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)
    B, monomials = G.coefficient_matrix()
    monomials = vector(monomials)
    factors = [monomial(*bounds) for monomial in monomials]
    for i, factor in enumerate(factors):
        B.rescale_col(i, factor)
    B = B.dense_matrix().LLL()
    B = B.change_ring(QQ)
    for i, factor in enumerate(factors):
        B.rescale_col(i, 1 / factor)
    H = Sequence([], f.parent().change_ring(QQ))
    for h in filter(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 []

n = 0x067f0aa4e974a63a1ffe8d5c23e5d3c431653ae41cc746f305f62a9f193f22486cb7ef1b275634818f46d0752a5139e19918271fa0d7d27bc660d2b72414d08ea52c8837f949c7baecc3029ba31727ef3bf120d9926c02d7412f187e98dc56dd07b987d2cc191ad56164a144f28b2f70a15d105588a4f27fbb2891fc527bd6890a5f795b5c48476a6bf9dfb67b7e1ebc7b1b086cd28b58c68955bfdf44ecce11ffacdf654551b159b7832040cc28ee8ebea48f8672d53e3de88fcfbb5fb276b503880dd34d5993335ddf8ccb96c1b4d79f502d72104765ad9c2b1858a17af3d5be44fa3cbf4b8eeb942aa3942a3871d2c65ac70289123fc2e9f9b25cbfcbd7841096060fa504c3a07b591493c64c88d0bb45285a85b5f7d59db98faa00c2cd3fbb63da599205f1cab0df52cf7b431a0ee4a7e35696546ce9d03ef595ecee92d2142c92e97d2744939703455b4c70dec27c321ec6b83c029622e83a9e0d55d0b258d95d4e61291865dda76dc619fce9577990429c6e77e9d40781e3b2f449701b83e8b0c6c66eb380f96473e5d422efee8b2b0e88b716b00a79c9d514ca3ad9d2dee526609ff9541732a4198d11b9dbfbb2e55c24d80ea522d0786e3355f23606a5d38a72de4eefc8b6bfc482248a2862cb69d8e0e3d316597da9d80828be85054faf15fc369caacafb815c6973c171940683d56a1a1967b09b7ffa3fbe5b2e08699759d84d71603f516447696bb27322a69f39f6ca253e00dc9555d5f97328070c467f3663cc489aad130f28c42f35bf88c571920ab92acb8f75d03e35a75103c5bd96f061c96bd02af6e1d191b0dd164bc721377003edbf5d3ef65a5e9046385356b521623bee37f164850a0a7afb0ed4e7e8bd9afe1298f7d532bc9ad941812d332aece75d1cccb1ff69fd42b31f248ae579d9e0d6a14b0546e784ba940e32bd01c395df8ff4584040462b5479fa07336d503dc332e70fc06d9463297fc042b623d56f87efaa525a9b580e314d90d1211893ed407a26508deaa0a13c9ee8c902b9e1c3a02fe9a51452c02ee7bdcc85c0eff63891e24703bd265d9c9dbf456e2af9409538bce0fecc7ebab20266aaab06c766c3ea6cda9cb9ba5e1d024b7dc3d73e76f6a333197bad87c4fb34d565a0014aac72825e41adcfeadadc87acef40ad84b7c55691abad561be0550ea0a988470c427432acb8feb2b9d2d2598fb2089bb91bbd9cb199e892d36164d8bf3ecd54576a97134047a12da84207485bb4e5
c = 4979484017431116007203595552962809215811680478766430242155223882705054545614042895123178821878874398696331660640694553985848505626114853588205730506953536258861781863676326881263249459930986331852232457947231504035893701678135866740704150494636561733749988050226581129057839191325170675208635964939328127784869025168003750110898106453205692226714493525204935288811571699406102981903479632430584373099221746484811556477787751775865158970753766248710738465250340219988598374091631879398149258909296956958871919793284601924214958117590017532687008743191626555554781510003550699693174014862415514876758743811245035623437410830966279638478179198985682007124038035199570324998857820805619829870448275930713559854062371837819573642989526005860119381892534582327602817126852775792795148406528289878749967688046692836828492838408885371655185020193077877863212194272859977914192718594242079083251651225528961805329778155563978529182964248473316859692375261884163394932168309723484649646366193294575262411749991785017839243084315564150440475352432754681704023380947915999673780390900873633978784233934847027345767542191158615451193815343145416211910292534809963195417241002543466881839686606566492374905537039788942235109098844473280282478821324700115239427316277552438411640200605928994972952882802751411650292005805556894082151965940003004477257067288284663988841213481538502089957444805715155156269544952438621610986537487935279293310826590792175130895814473225290270601604144041994343392084705733448031446703880658014942940650066718430558420050838062903533007823126002262054209453371718819329562924834276019205758413043184732567678745401759758652534654752694114698071548967168247400129347127567573092120202761561441510651361435039937371264757854420297670483231803771857824260496698681266025914759807273088103459245921523612515634715399325528015030838381172672985860784851184711821504752135277008040543609716627173356178738519121073783362475156943112906813634178018747875078004152082295842585904244592086520299047182968014176205665523399899710761547638531528036228248923871183095419308081144312924062869723612799638554108312833663396024784481057691024078417117543
ph = 0x8063d0a21876e5ce1e2101c20015529066ed9976882d1002a29efe0f2fdfcc2743fc9a4b5b651cc97108699eca2fb1f3d93175bae343e7c92e4a41c72d05e57019400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
qh = 0xe4f0fe49f9ae1492c097a0a988fa71876625fe4fce05b0204f1fdf43ec64b4dac699d28e166efdfc7562d19e58c3493d9100365cf2840b46c0f6ee8d964807170ff2c13c4eb8012ecab37862a3900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
e = 65537

R.<x,y> = PolynomialRing(Zmod(n))
f = (ph + x)^5 * (qh + y)^2
res = small_roots(f,(2^496,2^400),m=2,d=3)
print(res)
root = res[0]
p = ph + root[0]
q = qh + root[1]

phi = p^4*(p-1)*q*(q-1)
d = inverse(e,phi)
m = pow(c,d,n)
print(long_to_bytes(m))
#flag{06f68a6b-abd4-11ef-8697-5ebbf69eeefa}

RSA-noE

#coding:utf-8

from Crypto.Util.number import *
from libnum import* 
from secret import flag

flag = flag + '-'*(255-len(flag))

p = getPrime(512)
q = getPrime(512)
r = getPrime(512)
s = getPrime(512)
e = getPrime(80)
n = p*q*r*s
phi = (p-1)*(q-1)*(r-1)*(s-1)
d = inverse(e,phi)
dP = d%(phi//(p-1))
dQ = d%(phi//(q-1))
dR = d%(phi//(r-1))
dS = d%(phi//(s-1))
m = s2n(flag.encode())
c = pow(m,e,n)

print('p=',p)
print('q=',q)
print('r=',r)
print('s=',s)

print('dP=',dP)
print('dQ=',dQ)
print('dR=',dR)
print('dS=',dS)

print('c=',c)

p= 12667217818427166876490169961287155216595801080714011390637179620146789433615578890371545883325827638438860815659917432427678279927954613090571951329817847
q= 12850159594948991096535102313038121152501069918915623131669029380875634969749684033322200375524629000229314695043123677945108463807592290889113959997752907
r= 11852267575603616548555019081156863496907952781537809557421512571634164143352239737705208079243463634152574944624483179940386630245632084695992041513667341
s= 8884210220002535898494527550733836173178888865099383284037349434592465972177501662351226233028613238667977522747093359980633933206523346527468453367375189
dp= 708856889615710055205783991433282297617087184706434723897638880176756433756350165534068853039255348456328942626388631402400697808615866509741930048365824306009871846403841595090080065793555412018515357723794019205766056774530487256883243965450066666959402236446407245374692626692969264411830051801979709713179492756099281113705848153181158174037567810810078809375034592959392712655612730739963657781460376105698263652955426244080686468666059425415631535169685523
dq= 705665554604582832758623237099287556400962282123731880718631913811722727969466921646063541616736406832511505419212848957782691694495311681967967209469829703344110141237182899520583146245817039453804616129207593777810951646286103657780144205684531287272643084253982608224764509191592718480416596517093253211408322161527014331133138139014634171602231471827091321034556430168894435366492911399748441577496655808838092892342776925112851823832313925656674774888087603
dr= 1192187414389099600999552741010045413788922698258290529453731150063393451911105331762528535508227683098765484818736169297735682692274654196892788207388660850131250608104655391091795831400588366013062664836834936659850039234429565788656962972076932598982593119841165007170323883023386747744514441654239666333607147804594470971367091169557839040079491310590197047523943138403507161257142040115651720059058494843942706202306547105566468438891002646166490590534008323
ds= 829921932355879622733387019138950888201152780518699755385325897109520772577162080174908615128289659475375947341087265680006925724327425983023523285654576824952982371889403621900464053497081389107301660839069536870791477239645902713731658202993604310942306129778541700210194276950544908538212368437673687110036690497643727415101658861827584267024885035354861958669578527998112155473984427890083390960534518844524592454546143560771609414176934130799441130438407363
c= 11051163683752914130898108801031706087034578012949539215007385432275133697220543259099990816671553419707692483556457763541683852170606722029607657381412184950107653869498789351465977642749273204512815110110782332579871893727701573020168673635743970479135401984666068198524175229321444652530433822274847659982975859916924003240186276732688028049540665821012278591699883568662024948882044863670080656401538297554643813556900936384705557731216823076329573874604882499373723896315002353536181383538260319893777358194361777763184715886588003756114103534917565678310718420421879849851293152748027781243060238301475215529290

crt直接求d即可

from Crypto.Util.number import *
p= 12667217818427166876490169961287155216595801080714011390637179620146789433615578890371545883325827638438860815659917432427678279927954613090571951329817847
q= 12850159594948991096535102313038121152501069918915623131669029380875634969749684033322200375524629000229314695043123677945108463807592290889113959997752907
r= 11852267575603616548555019081156863496907952781537809557421512571634164143352239737705208079243463634152574944624483179940386630245632084695992041513667341
s= 8884210220002535898494527550733836173178888865099383284037349434592465972177501662351226233028613238667977522747093359980633933206523346527468453367375189
dp= 708856889615710055205783991433282297617087184706434723897638880176756433756350165534068853039255348456328942626388631402400697808615866509741930048365824306009871846403841595090080065793555412018515357723794019205766056774530487256883243965450066666959402236446407245374692626692969264411830051801979709713179492756099281113705848153181158174037567810810078809375034592959392712655612730739963657781460376105698263652955426244080686468666059425415631535169685523
dq= 705665554604582832758623237099287556400962282123731880718631913811722727969466921646063541616736406832511505419212848957782691694495311681967967209469829703344110141237182899520583146245817039453804616129207593777810951646286103657780144205684531287272643084253982608224764509191592718480416596517093253211408322161527014331133138139014634171602231471827091321034556430168894435366492911399748441577496655808838092892342776925112851823832313925656674774888087603
dr= 1192187414389099600999552741010045413788922698258290529453731150063393451911105331762528535508227683098765484818736169297735682692274654196892788207388660850131250608104655391091795831400588366013062664836834936659850039234429565788656962972076932598982593119841165007170323883023386747744514441654239666333607147804594470971367091169557839040079491310590197047523943138403507161257142040115651720059058494843942706202306547105566468438891002646166490590534008323
ds= 829921932355879622733387019138950888201152780518699755385325897109520772577162080174908615128289659475375947341087265680006925724327425983023523285654576824952982371889403621900464053497081389107301660839069536870791477239645902713731658202993604310942306129778541700210194276950544908538212368437673687110036690497643727415101658861827584267024885035354861958669578527998112155473984427890083390960534518844524592454546143560771609414176934130799441130438407363
c= 11051163683752914130898108801031706087034578012949539215007385432275133697220543259099990816671553419707692483556457763541683852170606722029607657381412184950107653869498789351465977642749273204512815110110782332579871893727701573020168673635743970479135401984666068198524175229321444652530433822274847659982975859916924003240186276732688028049540665821012278591699883568662024948882044863670080656401538297554643813556900936384705557731216823076329573874604882499373723896315002353536181383538260319893777358194361777763184715886588003756114103534917565678310718420421879849851293152748027781243060238301475215529290

n=p*q*r*s
phi = (p-1)*(q-1)*(r-1)*(s-1)
nn1=phi//(p-1)
nn2=phi//(q-1)
nn3=phi//(r-1)
nn4=phi//(s-1)
cc=[dp,dq,dr,ds]
nn=[nn1,nn2,nn3,nn4]
d=crt(cc,nn)
print(d)
print(long_to_bytes(pow(c,d,n)))#flag{5bd73913-792b-4247-a23b-fe73b1e096ec}
0 条评论
某人
表情
可输入 255