Path: blob/master/RSA-encryption/Attack-Coppersmith/Challenges/Really-Suspicious-Acronym/exploit.sage
1403 views
from Crypto.Util.number import *1from sage.all import *23c1 = 42497295412748323248319151018509780414919709589780133338929187233061687704720891964787205275549827649870796252180294450150428354129699866104077949625464865267683774644831622725417336245213502574583349123579615571415513765026791120697462502231301200676785036090543433069104816185024494877514678385687363957580644264033810687607014345854339156149017960407403168242836431775056771056190029291036193388763221834167505428485076314121066336309848675622432286590404037246713252360963197845254576743980198605585302129051261333785086767772005382750883872510387142203611733763551854492394834725453700431453251063076064318284494820781914c2 = 130758558454983843448202575598933093201258430931074425726807768722991022487438664206403235000877881632388193012601733221879781408667180362923855205097245064876920012457302986757316815094121775470613968619614137602980643855266571356562834647594793885908226007479031003541356826243564548722838528221171996417008475586057003701175578553969520830886454779667823383160173874067330633469862240148372464045815628133128556444241286483631757927862828571546247886254110701730925128341816787329142316696166705155127747093156202334825158211782776737378450326729938145001771260480198148773975473101669151883416684391017699324926773634634225flag = 13250709560091034892491946373475105885067296087841275119266288955433049404152970992076014986261819159018488628549950773154756742575933600126338183956990005018968967128556381149322748736367066795360941480848251132133486936691106845346121504349855891380036194940805565878825028822454805301482962330193061648329599247195300895394128786050512844929009191532915392857640672159544800464742371292470059109588545709366264946646740149707921831826212617769429521726435739559500741085553633338083304556482569160956192616202861207482664152192596653106373400925035231393798694460539822008584972315068924854194291786717431861482884072336576m1 = bytes_to_long("You can't factor the modulus")7m2 = bytes_to_long("If you don't know the modulus!")8e = 65537910N = 348252237434028293836803595478141832408176640709099386986746583903741247872357395026880566390221318977155135879034675270660655453996228345345136318671454325537308509803317899316673709033960327585156812780570314968140548284194438223439861177609581869845217168073471239499228374824605327283502234734307130585223611759805219088172158122912722842418480862601803826930147139013037474447538286365753513490268832949395610014680992525431813361957460327181779374174311017563138236351501296018553585586359963482712429203084062685526067336763017250883483992642939361516624674564108254023039215833891678820907674239317623478259078023280531112c = flag1314hidden = 50015tmp = isqrt((N)/(0xdead * 0xbeef))16print "tmp: ", tmp17q_approx = 0xbeef*tmp - 2**50018print q_approx1920F.<x> = PolynomialRing(Zmod(N), implementation='NTL')21f = x - q_approx2223roots = f.small_roots(X=2**hidden, beta=0.1)24for delta in roots:25print('delta', delta)26print('q_approx - delta', q_approx-delta)27q = q_approx-delta28p = int(N)/int(q)29d = inverse_mod(65537, (p-1)*(q-1))30print("d", d)31decrypted = hex(int(pow(c,d,N)))32print('flag =', decrypted[2:-1].decode("hex"))333435