-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrsa.py
27 lines (23 loc) · 2.29 KB
/
rsa.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import sys
import gmpy
from Crypto.Util.number import long_to_bytes
N=29305921737369886279038152431458707745355920195340790633550446377488686490512301178207697116246186778190924968443242727209192145361597954397703409338069729744292087169349435205477111519898623053938076788571744581299492224350113161859881956596600525450754261861393876554473809245794408742597102639891003381267790265467110910689556328239201649010942790888964428993459470671962067180710623140718060936541350682131434255836234235317518687234833999941547912869602186172312623135615225793969932093534558250060291946557717352685360398453623552366165987007320321792084111530716138710220857188412330321516912749540601365795149
e1=65536
e2=17
C1=7351998152923111470294124803066775015114683074072771445691080243371404973542712549680112494258904659021284374456291176201665809185171260050697762658547638310947833522734650580644111431387517021868886145969673994994716591904271646563517826585280383232287066954868541205059424614585428845307919787362897495337549933634385558421506937186185820371287482316083539135225148967053559960291030264396319218652703479364309149535233799468133301886274312241438268180090474799238264932143708688705810772181495694270516639597093030652163699128226440802332931824857648885820801895950120801191850508661128764709243443284561349709164
C2=27952544053645910147582022180342450282885002344383448723362590332685825671415469835713812120541190506151131601994364261174492251443820879825081178625888284653451572008519376369598562129059429679308925154199630941540325208556932476733240733751805502663573433099523015820987485758386252121503984513364148041158986990173791561162327386860971438879823904316485263675116762490504450175345331901821821433003998337422420001224349434352618899797013984526278675024775861893474452267297072366637072762253586134059639659957041091424010223606781616430556510087692794009282759707693423796813562129251344684444608024491992669686350
def common_modulus_attack(c1, c2, e1, e2, n):
gcd, s1, s2 = gmpy.gcdext(e1, e2)
if s1 < 0:
s1 = -s1
c1 = gmpy.invert(c1, n)
elif s2 < 0:
s2 = -s2
c2 = gmpy.invert(c2, n)
v = pow(c1, s1, n)
w = pow(c2, s2, n)
m = (v * w) % n
return m
if __name__ == '__main__':
m = long_to_bytes(common_modulus_attack(C1, C2, e1, e2, N))
print(m)