跳转至

MapleCTF2022 brsaby

brsaby

I put the rsa in the baby. Or did I put the baby in the rsa? Either of those things sounds illegal.

Author: zhengdw#3529

from Crypto.Util.number import getPrime, bytes_to_long
from secret import FLAG

msg = bytes_to_long(FLAG)
p = getPrime(512)
q = getPrime(512)
N = p*q
e = 0x10001
enc = pow(msg, e, N)
hint = p**4 - q**3

print(f"{N = }")
print(f"{e = }")
print(f"{enc = }")
print(f"{hint = }")

'''
N = 134049493752540418773065530143076126635445393203564220282068096099004424462500237164471467694656029850418188898633676218589793310992660499303428013844428562884017060683631593831476483842609871002334562252352992475614866865974358629573630911411844296034168928705543095499675521713617474013653359243644060206273
e = 65537
enc = 110102068225857249266317472106969433365215711224747391469423595211113736904624336819727052620230568210114877696850912188601083627767033947343144894754967713943008865252845680364312307500261885582194931443807130970738278351511194280306132200450370953028936210150584164591049215506801271155664701637982648648103
hint = 20172108941900018394284473561352944005622395962339433571299361593905788672168045532232800087202397752219344139121724243795336720758440190310585711170413893436453612554118877290447992615675653923905848685604450760355869000618609981902108252359560311702189784994512308860998406787788757988995958832480986292341328962694760728098818022660328680140765730787944534645101122046301434298592063643437213380371824613660631584008711686240103416385845390125711005079231226631612790119628517438076962856020578250598417110996970171029663545716229258911304933901864735285384197017662727621049720992964441567484821110407612560423282
'''

2 exp

hint = p**4 - q**3
N = p*q

--> 

hint*q**4 = N**4 - q**7

q**7 + hint*q**4 - N** 4 == 0
sage: q=var('q')
sage: solve(q^7 + hint*q^4 - N**4, q)
[q == 11248052945492193606877386307812298309646455365482356576580845624056836046347518805927852646289457003475918197991787867864250859819603651806169306473552239, 0 == q^6 + 11248052945492193606877386307812298309646455365482356576580845624056836046347518805927852646289457003475918197991787867864250859819603651806169306473552239*q^5 + 126518695064595612523936969173632568116238797250531428454236135771512287096105796392725372148550834175380324203304877619212978265919808399743767325192080914060027808622914812267670874604167516834025381311324163438805584895994386839795900493741397276453163254721095354180408143878252747297373963003991061913121*q^4 + 20172108941900018394284473561352944005622395962339433571299361593905788672168045532232800087202397752219344139121724243795336720758440190310585711170413894859542593235272214835659589915418569306386165807248110869079463911387267812052932393435807335804594744705022399412874682047226624263529568922176136736216663848567877928935376942721460844729114750470489971732337203550609349902551058326078115957339611018311218194487862182593566471280277569340203835717925459924435299269644425679709555803300845429605736920134196541560120029584658832295714411061028497662688193627215294867678473077768711372503139032576584633451201*q^3 + 226896949400727918853822990739820929536537911623758206414077003340076399445845330565602531054420615865295492825212178449837284306486656611052274911267291309949654009606171457734338791088577692471666099678233196607390720795060100683120169428819650396544736046319093601502501354074944049404429914697407097573135430196539950952191822344505467988064679040818417836950099644542663937185561454302379072119051710491361522600525630912261315859173040119358682200892864565163646107892462571846693749232412804623309308407347211178516790514743681935176383002297109489261527376655603028459799043695598400018986571904483738603364404902749626158181099271687028990165159349228628178318322116615617321696507242877998384079046186052579210608512234948801772826161219139405687180316530789039*q^2 + 2552148900030050880722484805593867600241129841929259379670144007774854177235066364026022156525382674972724048314203761886182547593743645028574591431238510601229890968855139572062267747786722497260685898235810021412147577798442268997393650119286044248366798529660030369329619519887142468545552280191998362672663410853775125692611098085907273703181066536982307845545525953789387999624420629274872463631819762937566177123418480932756994235303799096998935350597870339676996659663781188582832685132138196013350386138150606635264128866256418025837672974337634341108922318026965788572787267211410521923113258137228878310641417670431901238386373473756208166122858375621437314676773477023631996661029409760086091082020204740473200554988704929983561815307593265286104611204928504900147485210394670458567489720464897695115800552290403341234455990393910062190641055339907381478995777726164860824166017830689895365961488692920795855108321*q + 28706705952317675769804333697008715385297447059261811014474709759340929574189626579128754621674369397435943699175985091414960980642570383484795801402315951677408091127110213406522701827270706722810679771907358646388778782067312000133275845448225027050943773622295815532644571780491443046854624208542646618123580201860622566073874207349205932062140285685229428927609324244865915552991052359955281876443636899266242338353496735983672414120405980435269684240782559222938894539749103518786383541212073950837926321100851163428897720844986034951642927090438462787808717304921543938801396482469518742202236264487627994673381364723308363950993228951385704194040940931626323828080889219683541144782526953438251278430120146719927406863978641631358415904212354647211690164986459671940346136592891060918386174587083826234148546040136339536354423501374552573201628831136546339753396276587094466736712137579570537658673594411345275425907140901707128057456651157200028350884048114309549585987633722106912009932480052992132761307285721879801895381263533222327326495778357866149022243690997080719]


sage: d=inverse_mod(e,(p-1)*(q-1))
sage: d
51409127301773820672936341831577206262955040859032044685742397841713493209034300637682925203129295730051890684319679235821533867563201382264863507636386574260067420919262722036454693695014434385059214711914742218780474909694721499890811872967729856292491417083959072173869503461004980639717907134386181309369
sage: m=pow(enc,d,N)
sage: m
233635589922140507243648472475489502539214485863424705490240683572494244612147232489469313673424509
sage: from Crypto.Util.number import *
sage: long_to_bytes(m)
b'maple{s0lving_th3m_p3rf3ct_r000ts_1s_fun}'