from Crypto.Util.number import getPrime,bytes_to_long
p,q = getPrime(2048),getPrime(2048) e = 7 n = p*q m = bytes_to_long(open('flag.txt','rb').read().strip()) c = pow(m,e,n) print("c = ",c) print("n = ",n)
# c = 147693154873835354725007152781732424355869776162377337823960431913672366269917723916891506269449726723757821517328874729037838600793748824028829185409932536014732765063216715033843955453706710187792772702199448156372644163429786386035008302836467605094954587157232829525150652611067567669525072625329634860065850520051628272535479197120008981979404760445193750864902244921407742155742716289495581989134730376783828846663464819337418977287363028738701414486788851136608957124505485242331701209645216580641917007780811842757125048746184068597664780265422321550909392419865169775282217442331295071069272774722564587602419768461231775480847018941840911357926330143045826277813722919121117172763493242590521245640828462665947672485094793188432098216701511715232654611338293295459889814699850788048985878279440740712956248569068077253790198036918598519191892836075254345518967666166925163908185663991353344555402397055977817370082929420443034626201745027965444069777059760865359310439815816749939498993014457995041394803598825093836045546578310632172636478575946653375857640993393714607308326474003446154152048840071034349831168612740218034679021240949747357214453636633636662650940968576792518622437627529244515229173 # n = 553409369582823237678532685244026647155180191225879439432235077135813123637186465008813830373646133388592395760175777499266561095087891764348044063111935877931069321764391883899483374576303169645488542398590564148654412004383012178107972880058460460806768779452529433458826925606225797078653905380530651390617109384086518728626571028089036812787671647095695947167204428442727185744172445701874820612799168887428075695751162763647868386879374037826876671079326544820609721731078985096813307183878793033824330869698508952853770794414757655681370862323768018291030331209143189638496644361618184164228294031490537429556439588954274708598530042700988138862000054458742762198052079867259365645914383561162796796952346445529346145323567650621600171442575319262718389389870407629339714751583360252884338116164466349449862781112019462555743429653595045695696967783338371470032332852204294900011651434678829104876529439166176589508898757122660322523937330848536715937381297551894198974459004139082562228022412335520195652419375915216074658463954339332593244483927157329404652516225481116614815221154229491846087288087715884363786672244655901308480290011237244562251084095684531716327141154558809471185132979704992609461470501119328696999713829
from Crypto.Util.number import * from gmpy2 import *
e = 7 c = 147693154873835354725007152781732424355869776162377337823960431913672366269917723916891506269449726723757821517328874729037838600793748824028829185409932536014732765063216715033843955453706710187792772702199448156372644163429786386035008302836467605094954587157232829525150652611067567669525072625329634860065850520051628272535479197120008981979404760445193750864902244921407742155742716289495581989134730376783828846663464819337418977287363028738701414486788851136608957124505485242331701209645216580641917007780811842757125048746184068597664780265422321550909392419865169775282217442331295071069272774722564587602419768461231775480847018941840911357926330143045826277813722919121117172763493242590521245640828462665947672485094793188432098216701511715232654611338293295459889814699850788048985878279440740712956248569068077253790198036918598519191892836075254345518967666166925163908185663991353344555402397055977817370082929420443034626201745027965444069777059760865359310439815816749939498993014457995041394803598825093836045546578310632172636478575946653375857640993393714607308326474003446154152048840071034349831168612740218034679021240949747357214453636633636662650940968576792518622437627529244515229173 n = 553409369582823237678532685244026647155180191225879439432235077135813123637186465008813830373646133388592395760175777499266561095087891764348044063111935877931069321764391883899483374576303169645488542398590564148654412004383012178107972880058460460806768779452529433458826925606225797078653905380530651390617109384086518728626571028089036812787671647095695947167204428442727185744172445701874820612799168887428075695751162763647868386879374037826876671079326544820609721731078985096813307183878793033824330869698508952853770794414757655681370862323768018291030331209143189638496644361618184164228294031490537429556439588954274708598530042700988138862000054458742762198052079867259365645914383561162796796952346445529346145323567650621600171442575319262718389389870407629339714751583360252884338116164466349449862781112019462555743429653595045695696967783338371470032332852204294900011651434678829104876529439166176589508898757122660322523937330848536715937381297551894198974459004139082562228022412335520195652419375915216074658463954339332593244483927157329404652516225481116614815221154229491846087288087715884363786672244655901308480290011237244562251084095684531716327141154558809471185132979704992609461470501119328696999713829
withopen("flag.txt","r") as fs: flag = fs.read().strip()
m = bytes_to_long(flag.encode()) c = pow(m,e,p*q) print(c) # 63388263723813143290256836284084914544524440253054612802424934400854921660916379284754467427040180660945667733359330988361620691457570947823206385692232584893511398038141442606303536260023122774682805630913037113541880875125504376791939861734613177272270414287306054553288162010873808058776206524782351475805
e = 65537 q = 11727544912613560398705401423145382428897876620077115390278679983274961030035884083100580422155496261311510530671232666801444557695190734596546855494472819 c = 63388263723813143290256836284084914544524440253054612802424934400854921660916379284754467427040180660945667733359330988361620691457570947823206385692232584893511398038141442606303536260023122774682805630913037113541880875125504376791939861734613177272270414287306054553288162010873808058776206524782351475805
d = inverse(e,q-1) m = pow(c,d,q) print(long_to_bytes(m))
round = 2 flag = open("./secret", "rb").read().strip()
deff(m, key): m = m ^ (m >> 4) m = m ^ (m << 5) m = m ^ (m >> 8) m ^= key m = (m * 1145 + 14) % 2**64 m = (m * 1919 + 810) % 2**64 m = (m * key) % 2**64 return m
defenc(m, key, round): key = bytes_to_long(key) left = bytes_to_long(m[:8]) right = bytes_to_long(m[8:]) for i inrange(round): left, right = right, f(right, key) ^ left left, right = right, left return long_to_bytes(left).rjust(8, b"\x00") + long_to_bytes(right).rjust(8, b"\x00")
defpadding(m): mlen = len(m) pad = 16 - mlen % 16 return m + pad * bytes([pad])
defecb_enc(m, key): m = padding(m) mlen = len(m) c = b"" for i inrange(mlen // 16): c += enc(m[i * 16 : i * 16 + 16], key, round) return c
from Crypto.Util.number import * from gmpy2 import * from sympy import nextprime
c = b'\x0b\xa7\xc6J\xf6\x80T\xc6\xfbq\xaa\xd8\xcc\x95\xad[\x1e\'W5\xce\x92Y\xd3\xa0\x1fL\xe8\xe1"^\xad' key = b"wulidego"
deff(m, key): m = m ^ (m >> 4) m = m ^ (m << 5) m = m ^ (m >> 8) m ^= key m = (m * 1145 + 14) % 2**64 m = (m * 1919 + 810) % 2**64 m = (m * key) % 2**64 return m
defdec(c,key): key = bytes_to_long(key) right = bytes_to_long(c[:8]) left = bytes_to_long(c[8:]) for i inrange(2): left,right = f(left,key)^right,left return long_to_bytes(left) + long_to_bytes(right)
defecb_dec(c, key): m = b"" for i inrange(len(c) // 16): m += dec(c[i * 16 : i * 16 + 16], key) return m
withopen("flag.txt","rb") as fs: flag = fs.read().strip() assertlen(flag) == 72
m = int.from_bytes(flag,"big")
from Crypto.Util.number import getPrime, isPrime
defnext_prime(p): whileTrue: p += 2 if isPrime(p): return p
p = getPrime(2048) q = next_prime(p) n = p * q e = 65537 c = pow(m,e,n) print("n =",n) print("c =",c)
# n = 329960318345010350458589325571454799968957932130539403944044204698872359769449414256378111233592533561892402020955736786563103586897940757198920737583107357264433730515123570697570757034221232010688796344257587359198400915567115397034901247038275403825404094129637119512164953012131445747740645183682571690806238508035172474685818036517880994658466362305677430221344381425792427288500814551334928982040579744048907401043058567486871621293983772331951723963911377839286050368715384227640638031857101612517441295926821712605955984000617738833973829140899288164786111118033301974794123637285172303688427806450817155786233788027512244397952849209700013205803489334055814513866650854230478124920442832221946442593769555237909177172933634236392800414176981780444770542047378630756636857018730168151824307814244094763132088236333995807013617801783919113541391133267230410179444855465611792191833319172887852945902960736744468250550722314565805440432977225703650102517531531476188269635151281661081058374242768608270563131619806585194608795817118466680430500830137335634289617464844004904410907221482919453859885955054140320857757297655475489972268282336250384384926216818756762307686391740965586168590784252524275489515352125321398406426217 # c = 307746143297103281117512771170735061509547958991947416701685589829711285274762039205145422734327595082350457374530975854337055433998982493020603245187129916580627539476324521854057990929173492940833073106540441902619425074887573232779899379436737429823569006431370954961865581168635086246592539153824456681688944066925973182272443586463636373955966146029489121226571408532284480270826510961605206483011204059402338926815599691009406841471142048842308786000059979977645988396524814553253493672729395573658564825709547262230219183672493306100392069182994445509803952976016630731417479238769736432223194249245020320183199001774879893442186017555682902409661647546547835345461056900610391514595370600575845979413984555709077635397717741521573798309855584473259503981955303774208127361309229536010653615696850725905168242705387575720694946072789441481191449772933265705810128547553027708513478130258801233619669699177901566688737559102165508239876805822898509541232565766265491283807922473440397456701500524925191214292669986798631732639221198138026031561329502985577205314190565609214349344303324429408234237832110076900414483795318189628198913032900272406887003325858236057373096880675754802725017537119549989304878960436575670784578550
关注到q的生成过程:
1
q = next_prime(p)
因此p、q相差过小,n开根后简单爆破即可得到分解。
exp.py:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
from Crypto.Util.number import * from gmpy2 import *
e = 65537 n = 329960318345010350458589325571454799968957932130539403944044204698872359769449414256378111233592533561892402020955736786563103586897940757198920737583107357264433730515123570697570757034221232010688796344257587359198400915567115397034901247038275403825404094129637119512164953012131445747740645183682571690806238508035172474685818036517880994658466362305677430221344381425792427288500814551334928982040579744048907401043058567486871621293983772331951723963911377839286050368715384227640638031857101612517441295926821712605955984000617738833973829140899288164786111118033301974794123637285172303688427806450817155786233788027512244397952849209700013205803489334055814513866650854230478124920442832221946442593769555237909177172933634236392800414176981780444770542047378630756636857018730168151824307814244094763132088236333995807013617801783919113541391133267230410179444855465611792191833319172887852945902960736744468250550722314565805440432977225703650102517531531476188269635151281661081058374242768608270563131619806585194608795817118466680430500830137335634289617464844004904410907221482919453859885955054140320857757297655475489972268282336250384384926216818756762307686391740965586168590784252524275489515352125321398406426217 c = 307746143297103281117512771170735061509547958991947416701685589829711285274762039205145422734327595082350457374530975854337055433998982493020603245187129916580627539476324521854057990929173492940833073106540441902619425074887573232779899379436737429823569006431370954961865581168635086246592539153824456681688944066925973182272443586463636373955966146029489121226571408532284480270826510961605206483011204059402338926815599691009406841471142048842308786000059979977645988396524814553253493672729395573658564825709547262230219183672493306100392069182994445509803952976016630731417479238769736432223194249245020320183199001774879893442186017555682902409661647546547835345461056900610391514595370600575845979413984555709077635397717741521573798309855584473259503981955303774208127361309229536010653615696850725905168242705387575720694946072789441481191449772933265705810128547553027708513478130258801233619669699177901566688737559102165508239876805822898509541232565766265491283807922473440397456701500524925191214292669986798631732639221198138026031561329502985577205314190565609214349344303324429408234237832110076900414483795318189628198913032900272406887003325858236057373096880675754802725017537119549989304878960436575670784578550
p = iroot(n,2)[0] while(1): if(n % p == 0): q = n//p break p += 1 phi = (p-1)*(q-1) d = inverse(e,phi) m = pow(c,d,n) print(long_to_bytes(m))
withopen("flag.txt","rb") as f: flag = f.read().strip()
m = int.from_bytes(flag, "big") e = 65537
from Crypto.Util.number import getPrime
for x inrange(10): p = getPrime(1024) q = getPrime(1024) n = p * q c = pow(m, e, n)
print("n =", n) print("c =", c)
''' n = 17524722204224696445172535263975543817720644608816706978363749891469511686943372362091928951563219068859089058278944528021615923888948698587206920445508493551162845371086030869059282352535451058203615402089133135136481314666971507135484450966505425514285114192275051972496161810571035753943880190780759479521486741046704043699838021850105638224212696697865987677760179564370167062037563913329993433080123575434871852732981112883423565015771421868680113407260917902892944119552200927337996135278491046562185003012971570532979090484837684759828977460570826320870379601193678304983534424368152743368343335213808684523217 c = 6870605439714128574950893771863182370595667973241984289208050776870220326525943524507319708560433091378319367164606150977103661770065561661544375425887970907060665421562712515902428061727268441585629591525591001533188276465911918724808701356962871139957343861919730086334623932624184172272488406793955068827527130338853980609365042071290967556159598511667974987218999253443575482949258292953639729393456515185185102248985930422080581185292420347510600574229080211050520146551505605537486989306457793451086767402197128573781597156939709237045132856159368959981648969874765462190363842275826077556314448408825308218451 n = 24974121071274650888046048586598797033399902532613815354986756278905133499432183463847175542164798764762683121930786715931063152122056911933710481566265603626437742951648885379847799327315791800670175616973945640322985175516271373004547752061826574576722667907302681961850865961386200909397231865804894418194711076667760169256682834206788730947602211228930301853348503098156592000286467190760378847541148772869356389938999094673945092387627113807899212568399028514283219850734634544982646070106811651490010946670117927664594365986238107951837041859682547029079035013475238052160645871718246031144694712586073789250183 c = 10324627733161143472233272675096997859064721978612320424254305978486200326061730105384511258706433940176741256952824288120499229240005823611541292676234913505775165761543820764046537413943393325463602612485849366939102550336256797820440347815027443410399157963547486098366749815425187247171697678576246606105486928212486117878157055321965270364583625270716186820068538749425299073309429589410882809098930213978117176627031795312102177342499674234163614021182116065492884880492891668658240362567156235958605768725892407536211503981819707919444725863397622629226309480836486427388484176463279384813974310500625102568341 n = 14215826065753265334521416948225868542990756976323308408298887797364519400310818641526401662106853573185085731682502059761982246604277475488691297554851873224516934619888327644352138127883043558424300092247604877819821625587944308487310522092440517150600171819145803937177931473336108429889165189521078678397694303305705260759351843006130968234071638035667854938070597400634242396852782331461576526836227336952718230741560369621645218729592233657856104560425642219241082727756696967324334634822771842625681505869025740662258929200756109704988223034840699133778958569054445520305361142302393767439478256174414187983763 c = 415916446053083522663299405080903121619846594209033663622616979372099135281363175464579440520262612010099820951944229484417996994283898028928384268216113118778734726335389504987546718739928112684600918108591759061734340607527889972020273454098314620790710425294297542021830654957828983606433731988998097351888879368160881316237557097381718444193741788664735559392675419489952796677690968481917700683813252460912749931286739585465657312416977086336732056497161860235343155953578618273940135486362350057858779130960380833359506761436212727289297656191243565734621757889931250689354508999144817518599291078968866323093 n = 12221355905532691305226996552124162033756814028292708728711809229588190407700199452617060657420166395065565154239801465361510672853972152857415394695376825120759202857555325904640144375262531345320714166285999668052224661520834318497234299585219832943519644095197479639328120838919035625832361810964127485907587199925564724081163804724975965691571850962714258888527902920462746795712011579424322515292865504642938090200503979483095345893697972170153990274670257331483858538617460680462369680572833191232126527727222302641204529110948993583190295067970240051042000918629138767209918572311469915774910003970381965123241 c = 2248834602646305164283014556051672824689884721514190813323189875541899566338153534858709617544459297836048770439230174669883719627734394673012731609952869246171300132019334542245094425654362711870373095782083791160029789553806741967408922001051006100049326921742208757147339981269528740944842177729701945606827918253016001436218891580980192743564642120923356793292885805519110411357830040053435569937296612987581482128241218218550319154933831743819546558930918761162723110000328532730751591375727881221199739397698390594797621758011191224528339478784930214820615602510460640307707682865125229937141010351138099874025 n = 18152103454920389919231636321286527841833809319334215885641536161086810144890443857211776387914779781628740172079478910188540146498426564211851629962338413488555121865779016981727229209606498886170396500155102635962395243364899026418106378234307821492609778555173516000309435730752571818439328803899462791834490025768785383592935046996428331508608555503567191807692523852530836008436655164751054189301721070209363416058642811329040202582026786024825518381761299547703962502636888833428457116986351812252188468878701301184044948733274488264320930936362549028124581962244201377136969591119942276742760215403738913067567 c = 2797812094994121597295362327809389195134238119144547570610194659000554967367804835006774413888965325870488368112707535584687083342412367127561646136089638402907513075405746055834487062923240856950047936297155455745928810738711368950139327254040579266046642851362228893522740216519732851152162928545416236075387903789535000820423985522550638100049857678600662008021574841083416323980817348573062083159710189689337626277009675683473560325178417766400002763719953723259300977655801234386662217462862844994462505601804422871991694828697337752697234180117437785537788728412520613916334045368736691714704501962513954509705 n = 22877887459293720334652698748191453972019668578065068224653972884599636421200068659750242304040301306798039254241668648594556654589309801728248683586229288074709849246660525799452637187132633064172425677552176203292787732404537215347782229753837476655088638984496409603054524994383358547132112778403912563916886533181616856401929346567686400616307916690806467019665390260267596320840786982457521423178851498130935577260638269429250197050326097193841333205073650802709022947551398142692735680419453533128176592587955634333425401930362881423044363132586170013458300714163531162544301477356808388416864173949089028317961 c = 12271947322974809255127222556723394446467844330408506340843897575503534175121932185624776713618037572593449207329510171212097269297133492090526270770286000839978630002819714376964416081198925899119135271459404333829811516667576167576916805217016117373027245648473458331936273975110163065432285322832123169216976420362833557809289561705091817949915218278430834098156335989014645979633658818904753942786129126233956314517292746008579152368541316795082120147520597254020266752859205131887527661767589367756335766220841483940854397440079467053684289006956034944336788288196391829411432383541473132962783883758561108297747 n = 19844333358004073542783728196775487079202832688982038135532362073659058674903791697765527614270399097276261983744620537925712167578187109058145015032736796457938148615396547198728652435169126585595701228287449135664667959433491335769206692390262797325133960778920452511673878233190120432257482339068405290918739453464061987163074129048150451046315248186376609350095502130018696275764450248681787926130463463923862832714969425813770847493135627599129546112143050369344208092649256659330284904392961574494907186727388685504929586018639846040474616307662546605623294842316524163106100888851228858194942825157286544846177 c = 9531264751315473345056673937611382755236533664089452852716992791452558274873158812669513178040971923528201631609089069182049526587423864397527252061341857426422965190913745048414029690931254119437249218321954899956104589066479231204536856131403590472063496956452030342299863907499976917750846369802185896519725837163530049157920978007252920334447236842959033879772444475877613295594785710745889554296655932909212643500877218304116451889820444820534937901427158918411546484157737612926382420354101675658160847653151539420222526999426483473829341628599881460824765758346670633385844187252696874025582747177333702736465 n = 16956880944655068255446705024149899655327230949463546092744762226005904114738078692036960935391303255804754787864713189658290361949509917704853428701870609882427423574672772606814823959758208695540116440342488334213300943604780971422918744381486937517952553797134323570131582724393100092308466968491068503301604506186521656059375518680612292667310641047190088814753025794048591445267711939066523165042651430468971452726568222388482323097260496415484997546126185688914792795834046855221759289007609518312601640548469651358391745947588643697900883634533872314566389446271647587564348026861264979727062157272541149018781 c = 16110326928338602237561005337578085623028116490564329920738844771341250444164294693848130674347672763073995755532723894042946521372321947507527854966013459795492930736187058535665041545095683801386814190612817128504426590828954205050425979880047802547011117626354405687170961272200066258220699329112978151044633994329352673342582175349200008181837211288847301836681860817044391028992501763375849046751094019224570802498414368189170656992427042010362385494565216988561215657424755648213390551881450141899860811844684546992754530755092358644968088017107313907435586729574798046187046145596726569637758312033849476689378 n = 16472195897077185060734002588086375750797253422014472876266294484788862733424113898147596402056889527985731623940969291811284437034420929030659419753779530635563455664549165618528767491631867637613948406196511848103083967995689432928779805192695209899686072900265108597626632371718430059561807147486376536203800038054012500244392964187780217667805308512187849789773573138494622201856638931435423778275004491853486855300574479177472267767506041000072575623287557610576406578525902565241580838652860552046216587141709709405062150243990097835181557208274750462554811004137033087430556692966525170882625891516050207318491 c = 11867731823522211833301190385669833752050387304375114576570892885641949969365352586215693183003550684262313893105989683214739695968039039944442567581277252581988489020834299896625977474857889570528169919064941042132119301236852358823696947330423679033138054012027878783478922023431469564210485180679933264749281963405243082505688901662659030897104957499953192201440290084373968716271056483463909282407034181891901928790601973222643210525000717355062752079302291729448234374709852429885984987094307177760741403086538949190424454337896501402430653783597070178968921411867485584517214777073301007918941216316241784521708 n = 13890749889361612188368868998653029697326614782260719535555306236512452110708495623964530174188871342332417484996749651846510646453983388637377706674890018646246874688969342600780781646175634455109757266442675502522791531161284420286435654971819525519296719668701529481662071464145515727217108362496784024871976015116522898184301395037566514980846499856316532479656908169681719288258287756566886281183699239684997698487409138330229321935477734921670373632304542254938831218652340699024011371979519574576890581492623709896310465567043899767342676912434857372520308852745792360420376574037705943820090308501053778144141 c = 6250115196713939477947942995075509357173312813431601073354390451609559579925704891503987992181988654989477525811826607070378476102616752398280691012244301950194800995432882828020405062344160270290542566163969692748126314259624623341922057435728127596172871894887055305291345372720594481096374310285437492746765510292863238933163142677773310305789984897974266961231555124787205980411992251387207335655129551950825339766848166539671565212408741432649813058363660321480995187545006718837863674527475323414266732366507905974800565463011676462244368010182725161416783875646259625352308599198614681446394427674340328493047 n = 21457499145521259498911107987303777576783467581104197687610588208126845121702391694574491025398113729462454256070437978257494064504146718372095872819969887408622112906108590961892923178192792218161103488204912792358327748493857104191029765218471874759376809136402361582721860433355338373725980783308091544879562698835405262108188595630215081260699112737457564998798692048522706388318528370551365364702529068656665853097899157141017378975007689790000067275142731212069030175682911154288533716549782283859340452266837760560153014200605378914071410125895494331253564598702942990036163269043699029806343766286247742865671 c = 6269656777204332618433779865483197625538144405832409880710764183039800286008967127279281167109250083159801218370191973055663058165456565194979210256278526713608759141588082614531352489547674696723140599892318118960648862531538435596775798128845789504910467783731144808685373807716609662688064728614003904579841055786083326311313295311152563668422289435606771091246147867715987583149743032723028324394173498623642539175178996531881058274717907066845565199058931743481410454382746158558886667761300257488769795092777021292335562818583719708133179974425584610403335487082478848975656282384575767178925517257692365828720 '''
n = [n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11] c = [c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11]
for i inrange(len(n)): for j inrange(i): if(GCD(n[i],n[j]) != 1): p = GCD(n[i],n[j]) q = n[i] // p phi = (p-1)*(q-1) d = inverse(e,phi) m = pow(c[i],d,n[i]) print(long_to_bytes(m)) exit()
from pwn import * from Crypto.Util.number import *
''' 这一部分交互拿数据 r = remote("localhost",59807) p = 11008176197295908754556650686251647243706292498034472501168046085732945809887313362518690275918394335207633925834115240024616753739067618316748808578650362774171917441376968722226626556434005996618900469687913893028687318661542559912265616293448246676128025762514511346750336107659243985471781068580223900395847 p = str(p).encode() r.sendline(p) r.interactive() '''
#sage p = 11008176197295908754556650686251647243706292498034472501168046085732945809887313362518690275918394335207633925834115240024616753739067618316748808578650362774171917441376968722226626556434005996618900469687913893028687318661542559912265616293448246676128025762514511346750336107659243985471781068580223900395847 a_pub = 3041998234690140733154003929351315749694173007295647496020072713756720943209175213390528908881513815372353043112125543782015504010903067412373671589783193113333759484653654593846608999327295977564591176273803313231805537606967793412594198900106990579441541583887521372737380085485236123798080560570278014966702 b_pub = 5019111378107696236906829966236801209683272037829678336595795065089184558620835243572805945837441564532780156063311684567652666178983348141519659763620244199977854812815568555236825281860924772124922980859797186639597490335115982316718963668010854994814229912399401172971794319506936755236803999795167503841257 c = 5757579635901147336595005390089603141773004178520561180663592936976073539821329993954175682240078485514741790990274876586653742472291327751694366705347330014705598863958938830082576802663476872305215648921055853375365278016644634303502905192252207112762958399098960852167171887363633849097395446708067829178184
g = 7 a = discrete_log(mod(a_pub,p),mod(g,p)) b = discrete_log(mod(b_pub,p),mod(g,p))
m = int(c * pow(7,-(a*b),p) %p) print(long_to_bytes(m))
withopen("flag.txt","rb") as fs: flag = fs.read().strip()
p = getPrime(1024) q = getPrime(1024) n = p * q e = 0x609778981bfbb26bb93398cb6d96984616a6ab08ade090c1c0d4fedb00f44f0552a1555efec5cc66e7960b61e94e80e7483b9f906a6c8155a91cdc3e4917fa5347c58a2bc85bb160fcf7fe98e3645cfea8458ea209e565e4eb72ee7cbb232331a862d8a84d91a0ff6d74aa3c779b2b129c3d8148b090c4193234764f2e5d9b2170a9b4859501d07c0601cdd18616a0ab2cf713a7c785fd06f27d68dff24446d884644e08f31bd37ecf48750e4324f959a8d37c5bef25e1580851646d57b3d4f525bc04c7ddafdf146539a84703df2161a0da7a368675f473065d2cb661907d990ba4a8451b15e054bfc4dd73e134f3bf7d8fa4716125d8e21f946d16b7b0fc43 m = int.from_bytes(flag,"big") c = pow(m,e,n)
from Crypto.Util.number import * from gmpy2 import *
#1 n = 0xbaa70ba4c29eb1e6bb3458827540fce84d40e1c966db73c0a39e4f9f40e975c42e02971dab385be27bd2b0687e2476894845cc46e55d9747a5be5ca9d925931ca82b0489e39724ea814800eb3c0ea40d89ebe7fe377f8d3f431a68d209e7a149851c06a4e67db7c99fcfd9ec19496f29d59bb186feb44a36fe344f11d047b9435a1c47fa2f8ed72f59403ebb0e439738fd550a7684247ab7da64311690f461e6dce03bf2fcd55345948a3b537087f07cd680d7461d326690bf21e39dff30268cb33f86eeceff412cd63a38f7110805d337dcad25e6f7e3728b53ca722b695b0d9db37361b5b63213af50dd69ee8b3cf2085f845d7932c08b27bf638e98497239 c = 0x45a9ce4297c8afee693d3cce2525d3399c5251061ddd2462513a57f0fd69bdc74b71b519d3a2c23209d74fcfbcb6b196b5943838c2441cb34496c96e0f9fc9f0f80a2f6d5b49f220cb3e78e36a4a66595aa2dbe3ff6e814d84f07cb5442e2d5d08d08aa9ccde0294b39bfde79a6c6dcd2329e9820744c4deb34a039da7933ddf00b0a0469afb89cba87490a39783a9b2f8f0274f646ca242e78a326dda886c213bc8d03ac1a9150de4ba08c5936c3fe924c8646652ef85aa7ac0103485f472413427a0e9d9a4d416b99e24861ca8499500c693d7a07360158ffffa543480758cafff2a09a9f6628f92767764fa026d48a9dd899838505ae16e38910697f9de14 e = 0x609778981bfbb26bb93398cb6d96984616a6ab08ade090c1c0d4fedb00f44f0552a1555efec5cc66e7960b61e94e80e7483b9f906a6c8155a91cdc3e4917fa5347c58a2bc85bb160fcf7fe98e3645cfea8458ea209e565e4eb72ee7cbb232331a862d8a84d91a0ff6d74aa3c779b2b129c3d8148b090c4193234764f2e5d9b2170a9b4859501d07c0601cdd18616a0ab2cf713a7c785fd06f27d68dff24446d884644e08f31bd37ecf48750e4324f959a8d37c5bef25e1580851646d57b3d4f525bc04c7ddafdf146539a84703df2161a0da7a368675f473065d2cb661907d990ba4a8451b15e054bfc4dd73e134f3bf7d8fa4716125d8e21f946d16b7b0fc43
classContinuedFraction(): def__init__(self, numerator, denumerator): self.numberlist = [] # number in continued fraction self.fractionlist = [] # the near fraction list self.GenerateNumberList(numerator, denumerator) self.GenerateFractionList()
withopen("flag.txt", "rb") as fs: flag = fs.read().strip()
assertlen(flag) == 72 m = int.from_bytes(b"\xff" + flag + b"\xff", "big")
deflong2bits(long): bits = [] while long > 0: bits.append(long & 1) long >>= 1 returnlist(reversed(bits))
defgenkey(len): sum = 0 out = [] for i inrange(len): delta = random.randint(1, 10000) x = sum + delta out.append(x) sum += x return out
key = genkey(74 * 8)
withopen("key.txt", "w") as fs: fs.write(str(key))
defencrypt(m, keys): data = long2bits(m) assertlen(data) == len(keys) returnsum((k if (p == 1) else1) for p, k inzip(data, keys))
withopen("ciphertext.txt", "w") as fs: fs.write(str(encrypt(m, key)))
观察可以发现,这个背包密码用的是超递增序列,因此可以直接从尾部逐个判断是否在背包中。
exp.py:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
from Crypto.Util.number import *
key = c = 44096612931024003148407895164090667174657344536623354666642108463093659898867859567157728084018394988840266329206836985537987081415020571845239234014695335928717091578810470705259929
m = [] for i inrange(len(key)): if(c > key[len(key)-1-i]): m.append("1") c -= key[len(key)-1-i] else: m.append("0")
m = int("".join(m)[::-1],2) print(long_to_bytes(m))
defchall(input:Callable[[str],None], print:Callable[[str],None]): from hashlib import md5 from string import ascii_letters s = "".join(random.choices(ascii_letters, k=16)) h = md5(s.encode()).hexdigest() print(f"<!> md5(XXXXXXXX+{s[8:]}) == {h}") i = input("Give me XXXXXXXX: ") if md5((i + s[8:]).encode()).hexdigest() != h: print("<!> ACCESS DENIED <!>") return inst = LCG() print("Let's play a simple game! If you can guess the right number, I will give your the flag! You have 10 tries") for tries inrange(10): i = input(f"Give me a number, you have failed for {tries} times: ") ifint(i) == (right := inst()): print(f"Congurations! You win the game! Your flag is here: {flag}") else: print(f"Oh, you are wrong! The right number is {right}")
from pwn import * from hashlib import md5 from string import ascii_letters from Crypto.Util.number import *
r = remote("localhost",63150)
defproof_of_work(): temp = str(r.recvline().strip())[2:-1] for i in ascii_letters: for j in ascii_letters: for k in ascii_letters: for l in ascii_letters: s = i+j+k+l + temp[13:17] h = md5(s.encode()).hexdigest() if(h == temp[-32:]): r.sendline((i+j+k+l).encode()) return
proof_of_work()
x = [] for i inrange(5): r.sendline(b"1") t = r.recvuntil(b"number is") num = int(r.recvline().decode()) x.append(num) print(t) print(num)
def_block_hash(a, b, c, d): x, y, z, w = F(a, b, c), F(b, c, d), F(c, d, a), F(d, a, b) return (a ^ b ^ c ^ d ^ x ^ y ^ z ^ w) ^ 0xFFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF
from typing importCallable from random import randbytes from base64 import b64decode,b64encode from hashlib import md5 from string import ascii_letters from random import choices
withopen("flag.txt", "r") as f: flag = f.read().strip()
s = "".join(choices(ascii_letters, k=16)) h = md5(s.encode()).hexdigest() print(f"<!> md5(XXXXXXXX+{s[8:]}) == {h}") i = input("Give me XXXXXXXX: ") return md5((i + s[8:]).encode()).hexdigest() == h ifnot proof_of_work(): print("<!> ACCESS DENIED <!>") return
b = randbytes(256) print(f"this is a random bytes: {b64encode(b).decode()}") i = input("give me another bytes with the same hash: ") try: d = b64decode(i) except: print("invaild input") ifhash(b) == hash(d) and d!=b: print(f"congurations! and your flag is {flag}")
def_block_hash(a, b, c, d): x, y, z, w = F(a, b, c), F(b, c, d), F(c, d, a), F(d, a, b) return (a ^ b ^ c ^ d ^ x ^ y ^ z ^ w) ^ 0xFFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF
from pwn import * from hashlib import md5 from string import ascii_letters from Crypto.Util.number import * from base64 import b64decode,b64encode #context.log_level = 'debug' r = remote("localhost",65309)
defproof_of_work(): temp = str(r.recvline().strip())[2:-1] for i in ascii_letters: for j in ascii_letters: for k in ascii_letters: for l in ascii_letters: s = i+j+k+l + temp[13:17] h = md5(s.encode()).hexdigest() if(h == temp[-32:]): r.sendline((i+j+k+l).encode()) return
proof_of_work()
r.recvuntil(b"this is a random bytes:") data1 = r.recvline().strip() #print(data1) data2 = b64decode(data1) data3 = b"" for i inrange(4): ta = data2[i*64:i*64+16] tb = data2[i*64+16:i*64+32] tc = data2[i*64+32:i*64+48] td = data2[i*64+48:i*64+64] data3 += (tc+td+ta+tb) #r.interactive() r.sendline(b64encode(data3)) #print(len(data3)) print(r.recvline())
from Crypto.Util.number import * from gmpy2 import * from sympy import nextprime
N = 363364907814244019888662301376841344262476227242899756862391470731421569394957444030214887114615748277199649349781524749919652160244484352285668794188836866602305788131186220057989320357344904731322223310531945208433910803617954798258382169132907508787682006064930747033681966462568715421005454243255297306718356766130469885581576362173340673516476386201173298433892314145854649884922769732583885904512624543994675379894718657682146178638074984373206937523380103438050549181568015985546172618830480078894445808092527561363650503540062128543705172678754195578429520889784813733491180748361345720247750720179608752244490362713103319685024237941527268458213442611663415417005556439749055222361212059968254748751273361732365487788593341859760309778894350385339764442343374673786357175846291309425081492959910254127778240522152676060766139057453197528944251599979227271074508795482632471242983094008619339488744362509349734218480932255216087706001484182136783834973304870508270118505737767002256270427907341952256516206663258530300791364944105025764611810001781971638030661367630116818647252727909489405550104641122269772492252464714694507693447974171377200402508765841829763548525530878309985480248379655169722567051495205792089930014228403456098065971372039443284193603395249634283366194562380309469628114581468645669390610963076340643757972439104287127375438663839421605531570285615180251 phi = 363364907814244019888662301376841344262476227242899756862391470731421569394957444030214887114615748277199649349781524749919652160244484352285668794188836492373364350673588273863828369502073826782362255108313852264064760467561392054178047091483873483255491431451728274259516789065331176728192953741805933100379191778599394515981288225535175013258094287912195847642598436035132783919453991516358280321085873745330313812205910011387125778714795906023110368957596998222544234082487264006696812862179916726781327290284827659294751262185328816323311831349296593013038823107653943652771448719760448938995150646738377177532550757319539185878535087009904848382493668686831331474113789651777885239747000076063679062106375348803749466079052774597412239427050432901553466002731972993029311850718200685157193170716432600165476733200831046297530470544781309612128231925681374239849452623513538498417735984094919756374577623486416462101457492789215144166273775249387638107644634704270216130852885082174564648445147377239033930079759024399532146184753110240154062693457622208373371290126810856885343328090305620627668495081760346853701632815149478447405718664667978825807101325764916405446176183238866136433205933785973568759281210319422288153910340542098573782006262190181726245838857185687242960093445000287347616796984610291664809895901301187179157382169999966124177588884152267266994164841066291200 n = 899081756851564072995842371038848265712822308942406479625157544735473115850983700580364485532298999127834142923262920189902691972009898741820291331257478170998867183390650298055916005944577877856728843264502218692432679062445730259562784479410120575777748292393321588239071577384218317338474855507210816917917699500763270490789679076190405915250953860114858086078092945282693720016414837231157788381144668395364877545151382171251673050910143023561541226464220441 e = 65537 c = 841335863342518623856757469220437045493934999201203757845757404101093751603513457430254875658199946020695655428637035628085973393246970440054477600379027466651143466332405520374224855994531411584946074861018245519106776529260649700756908093025092104292223745612991818151040610497258923925952531383407297026038305824754456660932812929344928080812670596607694776017112795053283695891798940700646874515366341575417161087304105309794441077774052357656529143940010140
from random import randrange
deffactorize(N, phi): """ Recovers the prime factors from a modulus if Euler's totient is known. This method only works for a modulus consisting of 2 primes! :param N: the modulus :param phi: Euler's totient, the order of the multiplicative group modulo N :return: a tuple containing the prime factors, or None if the factors were not found """ s = N + 1 - phi d = s ** 2 - 4 * N p = int(s - iroot(d,2)[0]) // 2 q = int(s + iroot(d,2)[0]) // 2 return p, q
deffactorize_multi_prime(N, phi): """ Recovers the prime factors from a modulus if Euler's totient is known. This method works for a modulus consisting of any number of primes, but is considerably be slower than factorize. More information: Hinek M. J., Low M. K., Teske E., "On Some Attacks on Multi-prime RSA" (Section 3) :param N: the modulus :param phi: Euler's totient, the order of the multiplicative group modulo N :return: a tuple containing the prime factors """ prime_factors = set() factors = [N] whilelen(factors) > 0: # Element to factorize. N = factors[0]
w = randrange(2, N - 1) i = 1 while phi % (2 ** i) == 0: sqrt_1 = pow(w, phi // (2 ** i), N) if sqrt_1 > 1and sqrt_1 != N - 1: # We can remove the element to factorize now, because we have a factorization. factors = factors[1:]
p = gcd(int(N), int(sqrt_1 + 1)) q = N // p
if is_prime(p): prime_factors.add(p) elif p > 1: factors.append(p)
if is_prime(q): prime_factors.add(q) elif q > 1: factors.append(q)
# Continue in the outer loop break
i += 1
returntuple(prime_factors)
primelist = factorize_multi_prime(N,phi) plist = [] for i in primelist: if(n % nextprime(i) == 0): plist.append(nextprime(i))
phi_n = 1 for i in plist: phi_n *= (i-1) d = inverse(e,phi_n) m = int(pow(c,d,n)) print(long_to_bytes(m))
from Crypto.Util.number import * from os import urandom
round = 2 flag = open("./secret", "rb").read().strip()
deff(m, key): m = m ^ (m >> 4) m = m ^ (m << 5) m = m ^ (m >> 8) m ^= key m = (m * 1145 + 14) % 2**64 m = (m * 1919 + 810) % 2**64 m = (m * key) % 2**64 return m
defenc(m, key, round): key = bytes_to_long(key) left = bytes_to_long(m[:8]) right = bytes_to_long(m[8:]) for i inrange(round): left, right = right, f(right, key) ^ left left, right = right, left return long_to_bytes(left).rjust(8, b"\x00") + long_to_bytes(right).rjust(8, b"\x00")
defpadding(m): mlen = len(m) pad = 16 - mlen % 16 return m + pad * bytes([pad])
defecb_enc(m, key): m = padding(m) mlen = len(m) c = b"" for i inrange(mlen // 16): c += enc(m[i * 16 : i * 16 + 16], key, round) return c
deff(m, key): m = m ^ (m >> 4) m = m ^ (m << 5) m = m ^ (m >> 8) m ^= key m = (m * 1145 + 14) % 2**64 m = (m * 1919 + 810) % 2**64 m = (m * key) % 2**64 return m
deff(m, x): m = m ^ (m >> 4) m = m ^ (m << 5) m = m ^ (m >> 8) return (((x^m)*1145+14)*1919+810)*x % (2**64)
defmagic1(x): m = bytes_to_long(b'\x9e\xb0)\x98R\x1c\xb3h') return f(m,x)
defmagic2(x): m = bytes_to_long(r) return f(m,x)
defkkp_sol(): x = BitVec('x',64) sol = Solver() sol.add(magic2(x) == bytes_to_long(b'\x9e\xb0)\x98R\x1c\xb3h') ^ bytes_to_long(r)) sol.add(magic1(x) == bytes_to_long(b"\xd3\xdc\xb4\x83P\xda5\xac") ^ bytes_to_long(l)) sol.check() print(sol.model())
kkp_sol()
key = long_to_bytes(3779692691923971252) c = b'B\xf5\xd8gy\x0f\xaf\xc7\xdf\xabn9\xbb\xd0\xe3\x1e0\x9eR\xa9\x1c\xb7\xad\xe5H\x8cC\x07\xd5w9Ms\x03\x06\xec\xb4\x8d\x80\xcb}\xa9\x8a\xcc\xd1W\x82[\xd3\xdc\xb4\x83P\xda5\xac\x9e\xb0)\x98R\x1c\xb3h'
deff(m, key): m = m ^ (m >> 4) m = m ^ (m << 5) m = m ^ (m >> 8) m ^= key m = (m * 1145 + 14) % 2**64 m = (m * 1919 + 810) % 2**64 m = (m * key) % 2**64 return m
defdec(c,key): key = bytes_to_long(key) right = bytes_to_long(c[:8]) left = bytes_to_long(c[8:]) for i inrange(2): left,right = f(left,key)^right,left return long_to_bytes(left) + long_to_bytes(right)
defecb_dec(c, key): m = b"" for i inrange(len(c) // 16): m += dec(c[i * 16 : i * 16 + 16], key) return m