Files
crypto2025/crypto-asimmetric/RSA-3/attack.py
2025-06-02 19:35:30 +02:00

33 lines
4.5 KiB
Python

from Cryptodome.Util.number import bytes_to_long, getPrime
import numpy as np
from gmpy2 import gcd
def egcd(a, b):
if (a == 0):
return (b, 0, 1)
else:
g, y, x = egcd(b%a, a)
return (g, x - (b//a) * y, y)
#The array mods are the N utilized
NArr = [121720186806296997800979538534610838374734751334685912810089377215004504057011542815350249589409126571557756347530275377081347144107627877648585982070305444757428430884386644436796681950522231862132460974829459908011848164947235675260429548827529963885145183776175424511145093559808770680388618014964869201199, 115798264708831001509831452282652377117247913406230481173932971530311207138289505609425951644808355060285770269148892080753105106723888042934884834817949996297119038125679794627407921510845406549274278284300830810036526628513928381076981701488991050846914184755737210682948322006955552194206666221556530254069, 129891916645136766954990840071239136459207498813379400672601426578831847656212739760321974414319624780647238243520795621558507340321036960603641016783930001933214554952892980985719766490723702259591820740126106443296808948516725137803993618809971215369272805623068723219777577178592979685247152887369080213469, 97440042627604058119462166311098928079074460477896227193167136164982689015461458211418231427974720780154163727230020238900390489255635496740913390712432413745693887138227178349326834808464939377520843058378484137633039051861149301719616738305187923502768381441541843160895988360219120088573263132711946135549, 118336797456007073778845583425765727519290931431629708341588136084005536094639394444055480793346537253211044225267352801744305543944594258715651884862219847349035909104973416940104288422933727439470796894321119143142352295983873128834400237669322455310392240839827948103230966843721381138542886809256064478583, 98830801478619438580886979231071793416086374828762996995335166178033453794813501043909349956992551774283648522075968950157876919261226385391203458862082192940317067631456258474770737562985117345952159996038314281257462262391260021194541096637417576244012229535327312563436777296722806384925044244352631380237]
c = [20895232551321355357796559134923739063229897004564726534442560232700008579832934464588215412298797749098926607008145809365713546063372794478172028895900292570052597729451835013404932658115272822381857334883139192842405577893328881755205525477692528232932048522246106064845149790024188650659712186587302788822, 27487798811245911704259308821426340722272943834169278939573060705897180221981687550608201257369881749684155124541223818713952131057624098178538068959839121916786988723255740240218509529169521298543759721788383816540422333430292030883380440242469234903193688320192413698212154775026244244196587629215529349439, 122927173440180953444662433474083795911421352764116743651940370614018966430157645895292514403617065522903149995860646654893791607848456961010416154477471279012016689725167398900740981766252818136656875685057173271127364782254020078195020269591458290777871967505852847729147604365960804210570303285847704383838, 44233148033940554518432069693759033772383557137256208049342336728964649128201129418248029048455077888784420944572193219780439638707817230248572975335198314036583478516348610748201061630538604305891410474498186918257941528933343064918770597617988984498416891802978664061022237210655046967332587866256202949892, 93945101865165834651030752141276949991568628433520700392114189816600544396582708855981883777442770327027947418039728898637860073054781023087929128993917266453956464368053124527395745452407733825804653717528957214721157125830092515381862283410183665194322787464290673344883392992558759324619716952152651997162, 22730706116732432827726070874241713593369489580689310920350655818718408738470892188020509332323278263964591696394047978191938035115889175060327324556077501151083828817726795434554236484206095214626725550236661310998674664814342644753736805886350007323393028684328815053810466996924583341348546738433492053843]
print(f"LEN:{len(NArr)}")
e = 65537
# I can try to find a common prime then it's the same thing
for i in range(len(NArr)):
for j in range(len(NArr)):
if(i!=j):
p1 = gcd(NArr[i],NArr[j])
if(p1 != 1):
p2 = NArr[i] // p1
p3 = NArr[j] // p1
#print(f"P2:{p2} and P3:{p3}")
phi = (p1-1)*(p2-1)
res = egcd(e, phi)
u = res[1]
decrypted = pow(c[i],u,NArr[i])
print(decrypted.to_bytes(decrypted.bit_length()//8+1,byteorder='big').decode())
break