-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrsa129.py
26 lines (20 loc) · 921 Bytes
/
rsa129.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
import functools
import eea
import sqmul
n = 114381625757888867669235779976146612010218296721242362562561842935706935245733897830597123563958705058989075147599290026879543541
e = 9007
p = 3490529510847650949147849619903898133417764638493387843990820577
q = 32769132993266709549961988190834461413177642967992942539798288533
y = 91045328916998417442482698097341808065794629308863274299915006508648723904695483923175519319873972294295937946793571148693700025
# y = 96869613754622061477140922254355882905759991124574319874695120930816298225145708356931476622883989628013391990551829945157815154
phiN = (p - 1) * (q - 1)
d = eea.multiplicative_inverse(e, phiN)
x = sqmul.sq_mul(y, d, n)
encoding = dict([(code-ord('a')+1, chr(code)) for code in range(ord('a'), ord('z')+1)])
encoding[0] = ' '
plain = str(x)
decoded = ''
while len(plain) > 0:
decoded += encoding[int(plain[:2])]
plain = plain[2:]
print(decoded)