e = 2 n = 87924348264132406875276140514499937145050893665602592992418171647042491658461 p = 275127860351348928173285174381581152299 q = 319576316814478949870590164193048041239 c = 45617141162985597041928941111553655146539175146765096976546144304138540198644
e = 2 n = 87924348264132406875276140514499937145050893665602592992418171647042491658461 p = 275127860351348928173285174381581152299 q = 319576316814478949870590164193048041239 c = 45617141162985597041928941111553655146539175146765096976546144304138540198644 m=[] mp=pow(c,(p+1)//4,p) mq=pow(c,(q+1)//4,q) qq=gmpy2.invert(p,q) pp=gmpy2.invert(q,p) m.append(long_to_bytes((mp*q*pp+mq*p*qq)%n)) m.append(long_to_bytes((mp*q*pp-mq*p*qq)%n)) m.append(long_to_bytes((-mp*q*pp+mq*p*qq)%n)) m.append(long_to_bytes((-mp*q*pp-mq*p*qq)%n)) for i in m: ifb'flag'in i: print(i)#b'flag{R0bin_rsa_666666}'
e = 0x3 n = 0x52d483c27cd806550fbe0e37a61af2e7cf5e0efb723dfc81174c918a27627779b21fa3c851e9e94188eaee3d5cd6f752406a43fbecb53e80836ff1e185d3ccd7782ea846c2e91a7b0808986666e0bdadbfb7bdd65670a589a4d2478e9adcafe97c6ee23614bcb2ecc23580f4d2e3cc1ecfec25c50da4bc754dde6c8bfd8d1fc16956c74d8e9196046a01dc9f3024e11461c294f29d7421140732fedacac97b8fe50999117d27943c953f18c4ff4f8c258d839764078d4b6ef6e8591e0ff5563b31a39e6374d0d41c8c46921c25e5904a817ef8e39e5c9b71225a83269693e0b7e3218fc5e5a1e8412ba16e588b3d6ac536dce39fcdfce81eec79979ea6872793 c = 0x10652cdfaa6b63f6d7bd1109da08181e500e5643f5b240a9024bfa84d5f2cac9310562978347bb232d63e7289283871efab83d84ff5a7b64a94a79d34cfbd4ef121723ba1f663e514f83f6f01492b4e13e1bb4296d96ea5a353d3bf2edd2f449c03c4a3e995237985a596908adc741f32365
from Crypto.Util.number import * import gmpy2 import sympy
n = 706179551528927755973552706384396984481317254286311623624769899751819558939505945997955808655099027031705265588837771891194337168185947501511405516114316789503893959933022257186151153998659082999630884992772455511117927262369430907812434632575048530041321710852346187864765563420900774870186578367019792489105675914258590354238288703776693825560015115292267646952651167684102073917401094871598116344315029571542763276173097810446291806671655688989136095998847231743650883822652934830157399820589087316766825588604788059432668390768008074573747942247918780066903612446281491110881465924899154507579133581995992453624743 e = 12429651525304197013420279636711923981038125415166022519813412628507500580842180697305180388443706309048295378021377001474127573305660405451533036316536279 c = 489793409206127323003663138555459463734568805718348185967363875100820061051281866993789805632550567774469168536774422909001725853017677808173233286745121655492235683190912523018811907652176512184366843413364716154846998486548611626688519571323104191711209211363547146221376030907992798593852466452993901455418977825327230736672597253861620003629101553059002681884047091535001348201522250928398365221843609859032236259074731044818227022822220827819732951798250094840916333657668242504816809502947668786327917580504462518995597830910788447212750284065632411801331136555650318499485528208557551780877753450322260693177513
e = 65537 n = 248254007851526241177721526698901802985832766176221609612258877371620580060433101538328030305219918697643619814200930679612109885533801335348445023751670478437073055544724280684733298051599167660303645183146161497485358633681492129668802402065797789905550489547645118787266601929429724133167768465309665906113 dp = 905074498052346904643025132879518330691925174573054004621877253318682675055421970943552016695528560364834446303196939207056642927148093290374440210503657 c = 140423670976252696807533673586209400575664282100684119784203527124521188996403826597436883766041879067494280957410201958935737360380801845453829293997433414188838725751796261702622028587211560353362847191060306578510511380965162133472698713063592621028959167072781482562673683090590521214218071160287665180751
for i inrange(1,e): if (dp*e-1)%i==0and n%(((dp*e-1)//i)+1)==0:#(dp*e-1)%i是p-1,寻找整数p-1且n能被p整除 p=((dp*e-1)//i)+1 q=n//p phi=(p-1)*(q-1) d=gmpy2.invert(e,phi) m=pow(c,d,n) print(long_to_bytes(m)) break#跳出循环避免过多的运算 #b'flag{wow_leaking_dp_breaks_rsa?_98924743502}'
from Crypto.Util.number import getPrime p = getPrime(1024) q = getPrime(1024) n = p * q
例题:
1 2 3 4
e = 0x10001 p>>128<<128 = 0xd1c520d9798f811e87f4ff406941958bab8fc24b19a32c3ad89b0b73258ed3541e9ca696fd98ce15255264c39ae8c6e8db5ee89993fa44459410d30a0a8af700ae3aee8a9a1d6094f8c757d3b79a8d1147e85be34fb260a970a52826c0a92b46cefb5dfaf2b5a31edf867f8d34d2222900000000000000000000000000000000 n = 0x79e0bf9b916e59286163a1006f8cefd4c1b080387a6ddb98a3f3984569a4ebb48b22ac36dff7c98e4ebb90ffdd9c07f53a20946f57634fb01f4489fcfc8e402865e152820f3e2989d4f0b5ef1fb366f212e238881ea1da017f754d7840fc38236edba144674464b661d36cdaf52d1e5e7c3c21770c5461a7c1bc2db712a61d992ebc407738fc095cd8b6b64e7e532187b11bf78a8d3ddf52da6f6a67c7e88bef5563cac1e5ce115f3282d5ff9db02278859f63049d1b934d918f46353fea1651d96b2ddd874ec8f1e4b9d487d8849896d1c21fb64029f0d6f47e560555b009b96bfd558228929a6cdf3fb6d47a956829fb1e638fcc1bdfad4ec2c3590dea1ed3 c = 0x1b2b4f9afed5fb5f9876757e959c183c2381ca73514b1918d2f123e386bebe9832835350f17ac439ac570c9b2738f924ef49afea02922981fad702012d69ea3a3c7d1fc8efc80e541ca2622d7741090b9ccd590906ac273ffcc66a7b8c0d48b7d62d6cd6dd4cd75747c55aac28f8be3249eb255d8750482ebf492692121ab4b27b275a0f69b15baef20bf812f3cbf581786128b51694331be76f80d6fb1314d8b280eaa16c767821b9c2ba05dfde5451feef22ac3cb3dfbc88bc1501765506f0c05045184292a75c475486b680f726f44ef8ddfe3c48f75bb03c8d44198ac70e6b7c885f53000654db22c8cee8eb4f65eaeea2da13887aaf53d8c254d2945691
e = 0x10001 p_high = 0xd1c520d9798f811e87f4ff406941958bab8fc24b19a32c3ad89b0b73258ed3541e9ca696fd98ce15255264c39ae8c6e8db5ee89993fa44459410d30a0a8af700ae3aee8a9a1d6094f8c757d3b79a8d1147e85be34fb260a970a52826c0a92b46cefb5dfaf2b5a31edf867f8d34d2222900000000000000000000000000000000 n = 0x79e0bf9b916e59286163a1006f8cefd4c1b080387a6ddb98a3f3984569a4ebb48b22ac36dff7c98e4ebb90ffdd9c07f53a20946f57634fb01f4489fcfc8e402865e152820f3e2989d4f0b5ef1fb366f212e238881ea1da017f754d7840fc38236edba144674464b661d36cdaf52d1e5e7c3c21770c5461a7c1bc2db712a61d992ebc407738fc095cd8b6b64e7e532187b11bf78a8d3ddf52da6f6a67c7e88bef5563cac1e5ce115f3282d5ff9db02278859f63049d1b934d918f46353fea1651d96b2ddd874ec8f1e4b9d487d8849896d1c21fb64029f0d6f47e560555b009b96bfd558228929a6cdf3fb6d47a956829fb1e638fcc1bdfad4ec2c3590dea1ed3 c = 0x1b2b4f9afed5fb5f9876757e959c183c2381ca73514b1918d2f123e386bebe9832835350f17ac439ac570c9b2738f924ef49afea02922981fad702012d69ea3a3c7d1fc8efc80e541ca2622d7741090b9ccd590906ac273ffcc66a7b8c0d48b7d62d6cd6dd4cd75747c55aac28f8be3249eb255d8750482ebf492692121ab4b27b275a0f69b15baef20bf812f3cbf581786128b51694331be76f80d6fb1314d8b280eaa16c767821b9c2ba05dfde5451feef22ac3cb3dfbc88bc1501765506f0c05045184292a75c475486b680f726f44ef8ddfe3c48f75bb03c8d44198ac70e6b7c885f53000654db22c8cee8eb4f65eaeea2da13887aaf53d8c254d2945691
from Crypto.Util.number import * from secret import flag p = getPrime(512) q = getPrime(512) assert GCD(3, (p-1)*(q-1)) != 1 assertlen(flag) == 40 assert flag.startswith(b'flag{') assert flag.endswith(b'}') n = p*q m = bytes_to_long(flag[7:-1]+b'12345678900987654321') e = 3 c = pow(m, e, n)
print("n =", n) print("m =", m&((1<<350)-1)) print("c =", c)
''' n = 78143938921360185614860462235112355256968995028076215097413461371745388165946555700961349927305255136527151965763804585057604387898421720879593387223895933656350645970498558271551701970896688207206809537892771605339961799334047604053282371439410751334173463317244016213693285842193635136764938802757014669091 m = 1906077032611187208365446696459387107800629785754941498024021333398862239730761050657886407994645536780849 c = 50130000135496687335562420162077023127865865388254124043997590968769445787929013990729805222613912997653046528125102370938788632651827553831996692788561639714991297669155839231144254658035090111092408296896778962224040765239997700906745359526477039359317216610131441370663885646599680838617778727787254679678 '''
n = 78143938921360185614860462235112355256968995028076215097413461371745388165946555700961349927305255136527151965763804585057604387898421720879593387223895933656350645970498558271551701970896688207206809537892771605339961799334047604053282371439410751334173463317244016213693285842193635136764938802757014669091 m_low = 1906077032611187208365446696459387107800629785754941498024021333398862239730761050657886407994645536780849 c = 50130000135496687335562420162077023127865865388254124043997590968769445787929013990729805222613912997653046528125102370938788632651827553831996692788561639714991297669155839231144254658035090111092408296896778962224040765239997700906745359526477039359317216610131441370663885646599680838617778727787254679678 e = 3
defgetFullP(low_p, n): R. < x > = PolynomialRing(Zmod(n), implementation='NTL') p = x * 2 ^ bit + low_p root = (p - n).monic().small_roots(X=2 ^ 128, beta=0.4) if root: return p(root[0]) returnNone
defphase4(low_d, n, c): maybe_p = [] for k inrange(1, 4): p = var('p') p0 = solve_mod([3 * p * low_d == p + k * (n * p - p ^ 2 - n + p)], 2 ^ bit) maybe_p += [int(x[0]) for x in p0] # print(maybe_p)
bit = 486 n = 99233273001596380809501393613886417854988989363311895592445631124571940638105064581031336422148895730117448547059137492090852484233539441265373247940823283633017582469362503632785297924194187912199716752955609363457416190782142095008241313065484612071705711161086869849047664563205898255359661312582650481473 e = 3 c = 175676150266403937224898870626869248307097859453341599800113943191154294552011908698393750389195590199207971365632903719917006078351629939912360175671032635640354766675409868021903917260597989036476083685690139071290022752606720020238530580507331902326179201548484337939338062870542095137303322195300197 d1 = 66155515334397587206334262409257611903325992908874597061630420749714627092070043054020890948099263820078299031372758328060568322822359627510248831960548842374360111368587702677016263988651746874367056185352095585037936034196599496577057035033718066207964292781685419156037246789689219471468151618592221802699