-
Notifications
You must be signed in to change notification settings - Fork 0
/
pqrsa_decr.py
38 lines (28 loc) · 881 Bytes
/
pqrsa_decr.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
28
29
30
31
32
33
34
35
36
37
with open("./pubkey", "r") as f:
pubkey = int(f.read(), 16)
with open("./key_enc", "r") as f:
key_enc = int(f.read(), 16)
with open("./key_dec", "r") as f:
key_dec = int(f.read(), 16)
import gmpy2
import math
import sys
encrypted = gmpy2.powmod(11711737117, key_enc, pubkey)
def calc_list(target, modulo, redix = 8):
lst = [1]
for i in range(2**redix):
print(i)
lst.append(gmpy2.t_mod(gmpy2.mul(lst[-1], target), modulo))
return lst
def power(lst, exponent, modulo, redix = 8):
result = 1
while True:
ind = exponent & (2**redix - 1)
result = gmpy2.t_mod(gmpy2.mul(result, lst[ind]), modulo)
exponent = exponent >> redix
print(sys.getsizeof(exponent))
if exponent == 0:
break
return result
lst = calc_list(encrypted, pubkey, 8)
decrypted = power(lst, key_dec, pubkey, 8)