-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModifiedRSA_Decrypt.py
More file actions
47 lines (46 loc) · 1.05 KB
/
ModifiedRSA_Decrypt.py
File metadata and controls
47 lines (46 loc) · 1.05 KB
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
38
39
40
41
42
43
44
45
46
47
import tracemalloc
import datetime
import os
tracemalloc.start()
def gcd(a, b):
if b == 0:
return a
else:
return gcd(b, a % b)
p = 13
q = 31
r = 157
s = 173
n = p * q * r
totient = (p - 1) * (q - 1) * (r - 1)*(s-1)
e = d = -1
ct = 0
for i in range(2, totient):
if ct == 1:
break
if gcd(i, totient) == 1:
e = i
ct += 1
ed = 1
while True:
ed = ed + totient
if ed % e == 0:
d = int(ed / e)
break
with open("encrypted.txt", "r", encoding='utf8') as fin:
encmsg = fin.read()
# stime=datetime.datetime.now()
#print(f"\nThe encrypted message is :\n{encmsg}")
enc = [ord(i) for i in encmsg]
dec = [pow(i, d, n) for i in enc]
#print("\nThe decrypted message is :")
with open("decrypted.txt", "w", encoding='utf8') as fout:
for i in dec:
fout.write(chr(i))
#print(chr(i), end="")
# etime=datetime.datetime.now()
# print("Time taken for Decryption",etime-stime)
snapshot = tracemalloc.take_snapshot()
for stat in snapshot.statistics("filename"):
print(stat)
tracemalloc.stop()