[dasctf]crypto2

from Crypto.Util.number import *
from random import *
import uuid
FLAG = ("flag{" + str(uuid.uuid4()) + "}").encode()


p = getPrime(512)
q = getPrime(512)
n = p*q
r = getPrime(512)
a = randint(0,p)
b = randint(0,p)
E = EllipticCurve(GF(p),[a,b])
G1,G2 = [E.random_element(),E.random_element()]

m = bytes_to_long(FLAG)*r
e = 114514
c = pow(m,e,n)
print(f'a = {a}')
print(f'b = {b}')
print(f'G1 = {G1}')
print(f'G2 = {G2}')
print(f'c = {c}')
print(f'n = {n}')
print(f'r = {r}')
print(f"{len(FLAG)*8}")#42
"""
a = 7554923049368389758644984708809298518555119242320008478713904164350398682612808897964323584005858572739997846383801796695034896481260582848239965991742753
b = 2946077750078923793456485455517589561048301296801442028557935942237998881399173184913961577615214181492464251758058856421725550043005454923809621307532238
G1 = (8436626812026372798235183541459913915513573963935022129458372993166877719488885831480986172457194556510687511143531211908626069770655987499529586979438496 : 3150598009452660137412365376690438042004770612907563199820503859563172892483801508212614906857266089943545595529839058812385775921301062716230080964552698 : 1)
G2 = (2872475170767720405445078833249188803233627045738755005671233205345009462626176124708099494157631318275859559074848020716303443016904864796760187787612998 : 9531824810387642823880240528889266027493240584099454731327297565018388536726728311397366654129723874530578214572004326884864471712953622415213718471586721 : 1)
c = 79974955026953711127258155420887331960480429785562234073427706771800249907425991604039830065430575803926694223848984135829079839362825377476276970111973154781713770887349281960076531993388464851444366356232258785659455718885749915879004725637651690941993440504994815990953923434175552011788274362218204971372
n = 99595798174287106117699093896658640283840482997966550825499560185174276579009719053632465265506883834543903012371884566962769679179344140322952938229742090145873752324882298654126004655587566720599132001263303598799329574380709442144888301786540117881181142928843824568065019504187880984364327209317929153083
r = 9538085910398350435110561711946815282664968112608068391373283818732570417175002468178809315266173440346384446711373302558477236425177486695922675076385477
336
"""

wp

根据两个椭圆曲线上的点和ecc公式计算p,从而分解n

e与phi不互素,有限域开方解(貌似叫这个名字)rsa

a = 7554923049368389758644984708809298518555119242320008478713904164350398682612808897964323584005858572739997846383801796695034896481260582848239965991742753
b = 2946077750078923793456485455517589561048301296801442028557935942237998881399173184913961577615214181492464251758058856421725550043005454923809621307532238
G1 = (8436626812026372798235183541459913915513573963935022129458372993166877719488885831480986172457194556510687511143531211908626069770655987499529586979438496 , 3150598009452660137412365376690438042004770612907563199820503859563172892483801508212614906857266089943545595529839058812385775921301062716230080964552698 , 1)
G2 = (2872475170767720405445078833249188803233627045738755005671233205345009462626176124708099494157631318275859559074848020716303443016904864796760187787612998 , 9531824810387642823880240528889266027493240584099454731327297565018388536726728311397366654129723874530578214572004326884864471712953622415213718471586721 , 1)
c = 79974955026953711127258155420887331960480429785562234073427706771800249907425991604039830065430575803926694223848984135829079839362825377476276970111973154781713770887349281960076531993388464851444366356232258785659455718885749915879004725637651690941993440504994815990953923434175552011788274362218204971372
n = 99595798174287106117699093896658640283840482997966550825499560185174276579009719053632465265506883834543903012371884566962769679179344140322952938229742090145873752324882298654126004655587566720599132001263303598799329574380709442144888301786540117881181142928843824568065019504187880984364327209317929153083
r = 9538085910398350435110561711946815282664968112608068391373283818732570417175002468178809315266173440346384446711373302558477236425177486695922675076385477
e=114514
print(G1[0])
from Crypto.Util.number import *
p1=G1[0]**3+a*G1[0]+b-G1[1]**2
p2=G2[0]**3+a*G2[0]+b-G2[1]**2

print('gcd',GCD(p1,p2))
p=9563053412585125412004454343523515324695653560824137311673565720664058611549446784223762835004163834709588127159698053759168471558813773620299707743732319
q=10414644138996181230885420227206390424131452420331210431977451825173531744841662110750709791334371998334357747810555021769860156829586716746661071229941157
print('q',q)
assert n==p*q
print('check',GCD(e,(p-1)))
print('mod',(p-1)%e)
print(isPrime(p),isPrime(q))
import gmpy2
def rsa(p,q,e,c):
    assert GCD(e,(p-1)*(q-1))==1
    d=pow(e,-1,(p-1)*(q-1))
    m=pow(c,d,p*q)
    print(long_to_bytes(m))
    return m

#sage
R.<x> = Zmod(p)[]
f = x ^ e - c
f = f.monic()
res1 = f.roots()
print('res1',res1)
R.<x> = Zmod(q)[]
f = x ^ e - c
f = f.monic()
res2 = f.roots()
print('res2',res2)

r= 9538085910398350435110561711946815282664968112608068391373283818732570417175002468178809315266173440346384446711373302558477236425177486695922675076385477
res1=[(733089589724903586073820965792963746076789390539824437962807679954808310072656817423828613938510684864567664345751164944269489647964227519307980688068059059377123391499328155021524914773359906357153671313308407478602554319510265005085762860382683102940576377254668898119652133942180899304170329371707150164, 1), (678923693209704969852381465896650019425870260030383443168808423368601278880685781654734919678958092826800695579102973572447355792679848485826507692704568923813419881117766044423608229711484763917744685055881596752291255735808048270822124796786471676188662798449644642235738223466855946913879538299578053411, 1), (660147311087779881169338548239431864756054612093222666998714749603875812596923472248793683967669014397990139199125982652383529516284367882454604795633984744310817735291839918294987220579419849435923577095190063747058566440604560174772236817980884692508913814109640678513633481822665261866470516425285518285, 1), (656681791452498481654878002485070757012861926668381629152705461263764608739765714942200770232734120738697878503189820956143274111419030898383980731253182784661086554234440727684677249747860741931943770929571071514986737487620545162638141249825931408013949005076717924474881049785216136013509251488319927117, 1), (561634200460522548441571592444405305656486299630777500288946777401428565675621685143645766539546494757183424411676233243328896459121008394512864385381461601416842364770773986015469061716463481506742063309940039220834724151367845375195245551456554735236102965922407472562800115189890526203678874326289793386, 1), (523855729860851889306276946831707325654966799659419971520448260469324992736982246556398347232993411720682146837875080052611076416766800095923505800210207882786055877101711481659849019405604591067848093320332336464705973049736439281995689523942160283871387832933740244138033780213828909573276367363492479416, 1), (452900182350324645394395847267638113925741103910755278893324277011525974119646860179890955142636700494806732282459985420380030145373473199426467982810188731584443697329277404941404099390850352429776960314100205943189386609329123884794268027928641499784873014598307047385649837271871153730516499924907326391, 1), (416370840270302176660974325650517943145426999919261282193286142404178655729051589183139277588858670001090144796272169390365633208042166264602215868369443740484308138194802614266542495845026116458981772823239562965336426568684608791041112836390368657079922805426770894892558562813602601339340032501607476909, 1), (415121711750653986259101201654940133924221603939397750124825760079422401181007421592643535836083617458305454708658832229662210103019264900837109397638935012953657209660214900590221340670067523952418432762094850952735077742516293665730069986289396136048668366129437705942925977098013178518939090064725293698, 1), (374350165605081425148746685793120637325474206554845188409530082476947889392734021316375944344139500560536749012063348621966245700071777272257861879442907414106249944743486841972083642001920163764631575788319343002998139757149039708713099627493777332364552928705440787113844863245759659045732547084424923730, 1), (358739424119822160925074279999843108751315183984979249553277597477860420679922796107452669594371184304030915333687816322303243947892450247050118808625151645270873446755841313053878556361515804554057537962591412241278856797179801170508021218764054858204533933069025997987849745498624881677262879389897507711, 1), (317967877974249599814719764138023612152567786600426687837981919875385908891649395831185078102427067406262209637092332714607279544944962618470871290429124046423466181839113254435740857693368444366270680988815904291541918811812547213491050859968436054520418495645029079158768631646371362204056336409597137743, 1), (316718749454601409412846640142445802931362390620563155769521537550629654343605228240689336349652014863477519549478995553903856439922061254705764819698615318892815253304525540759419702518409851859707340927671192278940569985644232088180008009867463533489164056347695890209136045930781939383655393972714954532, 1), (280189407374578940679425118525325632151048286629069159069483402943282335953009957243937658795873984369760932063291179523889459502590754319881512705257870327792679694170050750084558098972585615888912153436810549301087609944999716994426852818329190690784213847176159737716044771472513386992478926549415105050, 1), (209233859864051696767544018961256420421822590880404466442359419485483317335674570867430266705517273143885517507876084891658413231197427423384474887857851176591067514397616673366113178957831377250841020430578418779571023504592401597225431322315671906697699028840726540963660828530555631149719059110829952025, 1), (171455389264381037632249373348558440420303090909046937673860902553379744397035132280182847398964190107384239934074931700940593188843219124795116302686597457960281026728554169010493136646972486811947050440970716023442272402960995504025875294801277455332983895852059312538894493554494014519316552148032638055, 1), (76407798272405104418942963307892989063927463871442808810102218691043701332891102481627843705776564125869785842561343988126215536545196620923999956814876274716036837264887427341284948615575226386745342821339683729290259066708295716582979596431900782555137856697748860626813558959168404709486174986002504324, 1), (72942278637123704904482417553531881320734778446601770964092930350932497475733345175034929970841670466577525146625182291885960131679859636853375892434074315066305656207488236730974977784016118882765536655720691497218430113724280704448884028276947498060173047664826106588061126921719278856524910049036913156, 1), (54165896515198616221439499896313726650919130509440994793999256586207031191971035769093694259552592037766968766648191371822133855284379033481472995363490135563703510381562110602353968651951204400944428695029158491985740818520792608398996049471360514380424063324822142865956385277528593809115888174744378030, 1), (4437283590076061961535442437602347765674442234818575874135357985875149087628510484519797886982042474802203641418825097102615281277, 1)]
res2=[(771182695213910447650732428220054698293987458796864628535794956332865106301119308051373568460701145677164052375651484670636989109023957702790185901445649197004100341656188532242400936626843773453840636251285728911675970163379867036690526519443109306012484303887302812373344206821914965170132246974771777444, 1), (766556454188661342717183441830753958949866417494716064331308873001400640185512932266682617111675304940672393843056881975135838366629757426494074139282338667675175892353840088889909195938963702112766349904198019372558645141384798583534383188883052267525748815134207587721641571601904662560056137622206973489, 1), (697252901173481151775023987079186148934671702095573239439077382532564148810196647295908000048808838516420504907242412420648310319468654564849006791509953203253591756022067984445917819993348421480837383431739473210443093160532003684668638512409524578887612424272056500338100724912084684072451333028872106867, 1), (637570615943233551403071638054753581415867520631437658239907745441121975126808316940174715476757666870531167942851357415707186407189108694841070152707092245309731475509435021166725640089960139181871460785130772780846084823629102758039859600829870217520667468256249544673326609044266687450424519008597139038, 1), (632327011426499994189315859401811158465010667761983995201046936822397685624551714172153350143852663041545272586491513748551456122474881151730273573849696707727190136249011496534362800230143294818909726182851035741169036440948865157971659975327810387018738693032165869052686855576696780303333160382173118510, 1), (603167942216453034450263940413887436639768290870012743059006350279961914111784943446402628202860617054930140073926171776018499373620898476085657301360306887162235526834606378738074341266663645930616670338128013164422994099750629106515540742416974080150559276654019646352903381932805758744985229930025215589, 1), (530466680163017973833308694998245966701824340964042532641356089137879243186221081260746979341797675072378875885003058544820764758046575857925699945279145064801793820479054735901259358468262299180565694104881447986591164582548172740211166270336596928161447369253455709413986912995034928572096835678138857265, 1), (465540790416036816247600567320870976232163306630453288403325643427712780000576148136992329436841499597503643564252159872723910561052802444806966727618888569275392200705998247985267055114981110557102594418390662751642665628146458339378829747379733648664063153493767191146530568857443383384153565928824587631, 1), (416074710242252176401044812192140737030784340427479537135890013577916016785682458613448218282243236911584933444225849145353809933396731357693587977285142052644526842758534194394543388181747428573306033684592492190246496510265285685848535401569621598453391802767037373579958843978087833160938909090562342099, 1), (394136899723687893136044300058080845383423389432958570785292421247573616646066598716388388801380799317671805332945423860473016951589636840148122537670603031835993896874831423637875155136425033395934564235988401408318773868625275203793169278596739058672957150515186335729596174779705646162358930520576725303, 1), (377045795490222554514688128161973852910564069363906057750502535085291489655052709334985179659320346359492247042706060810163972157434320862642063363775046165168106444781357108608963065080494802019441514452899675269031638529573167707032715226721519334968037637891914363625790506844412960426598413556810333418, 1), (355107984971658271249687616027913961263203118369385091399904942754949089515436849437925350178457908765579118931425635525283179175627226345096597924160507144359573498897654337852294832035172406842070045004295584487103915887933157224977349103748636795187602985640063325775427837646030773428018434986824716622, 1), (305641904797873631403131860899183722061824152166411340132469312905152326300543159914381239023859646079660408811399324797913078547971155257983219173826760627728708140950190284261571165101938724858273484270497413925707746770051984571447054757938524744976931634913333508208856112766675223204803778148562471090, 1), (240716015050892473817423733221808731592163117832822095894438867194985863114898226790626589118903470604785176490648426125816224350977381844864485956166504132202306521177133796345578861748657536234810384584006628690759247815650270170614718234981661465479547419153644989941399768629083678016860508399248201456, 1), (168014752997457413200468487806167261654219167926851885476788606052903192189334364604970940257840528622233912301725312894618489735403059226704528600085342309841864814821582153508763878950256189484759408350760063512927418298447813804310343762901284313490435511753081053002483299691312847843972114147361843132, 1), (138855683787410453461416568818243539828976791034880633334748019510467420676567593879220218316848482635618779789159970922085532986549076551059912327595952489276910205407177035712475419986776540596466352506037040936181375957249577752854224529990448006622256095374934830302699826047421826285624183695213940211, 1), (133612079270676896247660790165301116878119938165426970295887210891743131174310991111198852983943478806632884432800127254929802701834849007949115748738556951694368866146753511080112580126959696233504617903757303896504327574569340152786024904488388176120327320150851154682060072579851919138532825068789919683, 1), (73929794040429295875708441140868549359315756701291389096717573800300957490922660755465568411892307160743547468409072249988678789555303137941179109935695993750508585634120547800920400223571413934538695257148603466907319237666439226157245992908733814753382364135044199017285956712033922516506011048514951854, 1), (4626241025249104933548986389300739344121041302148564204486083331464466115606375784690951349025840736491658532594602695501150742394200276296111762163310529328924449302348443356929024277956133302609728784690057304791767256813644327291501316435206126115245973272893111633745110022213944028901206455180085232, 1), (4437283590076061961535442437602347765674442234818575874135357985875149087628510484519797886982042474802203641418825097102615281277, 1)]
import libnum
for i in res1:
    for j in res2:
        # 中国剩余定理
        m =libnum.solve_crt([int(i[0]),int(j[0])],[p,q])#c3=libnum.solve_crt([c1,c2], [q1,q2])
        if b'flag' in libnum.n2s(int(m)):
            print(libnum.n2s(int(m)))
print('done')

# b'flag{r54__d34l1n6_w17h_3v3n_3 _&_f1nd1n6_n-7h_r0075~~}'

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值