连分数攻击
两个n非常接近,考虑连分数攻击。
#python3 from Crypto.Util.number import * from gmpy2 import * n1 = 45965238261145848306223556876775641787109249067253988455950651872774381183888979035386577960806305813634216583223483001245996467366520071511779063266315692543617195166613592991812117446772937889819643718423377609566597230873623011099295202599905646652692946273375405832062164263711151844949794774229886016858313299259387152937467743637367261734624060321171598033647661809876890249035267180368762739600552966699295210431508056693524383116052539072065535970720901196322942269916455391238409489616842687658335666652878840458263998780783865062993401055465701207886230787204008073260653659510197069116237460322442433331870944968133645513020531983926180514313028320422449103156746225574626841023639595418255472716267486241462968101152032898749 e1 = 279586443815379026299414729432860797623 c1 = 11515318475856179010858377918435934663304239594599788732135470038988222237790835017056954077794506499559722814863240838882673078330335616745578747265404229105473136943188301293198548838105990504750972653445744347121859396823995101611868191609259910876207038154174100742978387355304521374228562928260479446249263909934393657537918407756957032700052269827171045167752168509783885071211516601218892308228572735545579606908430615218499620619028799140945676768341492724044499209913045110359935325510223652935426973411960865908064824205626343685369866932545651037748553442488682593143020861196339307665638704485958986411837014559504992818255506454051842453553265179370878637153602580071152915165775491633322055360737581203750897698007951117808 n2 = 25459365600568360055376316722846535809281537088824978187355135247184417413329012865221456308642116409716822227032113740366024809533942721286337697830775221199570509665320400376959076685728357107457862901087218522281771857981155239522807950207375964963527837592797198372303427082343684305143238075402697262610809363109748984974325271762535573995993132076293275456692621516174749076897962348000698039074721998780555541905706268579496243099763776676950336105074846695227221690550755501320117554250942600626927600558489780841103863110357615957088709321079080707735028039675102383525496673233697130053936053431067133520717494376952763684807635780416860233261892013531534059267366382617635000415723745274490604551078385404286689447761642713963 e2 = 249615977162294580923494787210301891647 c2 = 24544357952213952357056140974408354173440635791397720610932999473703241918398814255275362994811954064820912468224131892551724930677715676493892869921426790840199600798807085779112854131346378899855545138289836687048918660685766286852276199524789699567994154833159365800848535248059731927121269157841084905465048764152977389352561685340108834453730139893330210765986258703154334901509553990091592209268471594519326651914685843021165854654380119091009831071244459145750976193183411590207529489774630266528538380011000213950174694472355034075543687572037516433204151217601537869823709241020510051494619335852686100897182065588340025334679570763716458250649152257797833022586793526594784648938165537701256313728194521212887453997160504204832 def Continued_Fractions(x, y): if y == 0: return x, y a = [] i = x j = y while True: a.append(i // j) temp = j j = i % j if j == 0: break i = temp return a def Continued_Fractions_k(a): x = 0 y = 1 for i in a[::-1]: x , y = y, i * y + x return x,y #######注意 x在前,y在后 assert n1 > n2 x = n1 y = n2 a = Continued_Fractions(x, y) for i in range(1,len(a)): t1, t2 = Continued_Fractions_k(a[:i]) if GCD(t2, n1) != 1: q = GCD(t2, n1) break q1 = 2497674642342680924619597750195769521949279717226590384925710403236449682331313352438535526110438429730119230176423088669 p1 = iroot(n1 // q1, 2)[0] assert p1 * p1 * q1 == n1 p2 = next_prime(p1) d1 = inverse(e1, p1 - 1) d2 = inverse(e2, p2 - 1) print(long_to_bytes(pow(c1, d1, p1)) + long_to_bytes(pow(c2, d2, p2)))
