-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModifiedRSA_Encrypt.py
More file actions
48 lines (46 loc) · 1.09 KB
/
ModifiedRSA_Encrypt.py
File metadata and controls
48 lines (46 loc) · 1.09 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
48
import tracemalloc
import datetime
import os
tracemalloc.start()
def gcd(a, b):
if b == 0:
return a
else:
return gcd(b, a % b)
# stime=datetime.datetime.now()
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("input.txt", "r", encoding='utf8') as fin:
message = fin.read()
#print(f"The message in the file is :\n{message}")
msg = [ord(i) for i in message]
enc = [pow(i, e, n) for i in msg]
#print("\nThe encrypted message is :")
with open("encrypted.txt", "w", encoding='utf8') as fout:
for i in enc:
fout.write(chr(i))
#print(chr(i), end="")
# etime=datetime.datetime.now()
# print("Time taken for Encryption",etime-stime)
snapshot = tracemalloc.take_snapshot()
for stat in snapshot.statistics("filename"):
print(stat)
tracemalloc.stop()