-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDecryption.py
More file actions
69 lines (45 loc) · 1.67 KB
/
Decryption.py
File metadata and controls
69 lines (45 loc) · 1.67 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# coding: utf-8
class Decryption:
#reading Decrytion key file
def readDecryptKeyFile():
decryptFile = open('DecryptionKeyFile.txt', 'r')
for line in decryptFile:
fields = line.split(",")
d=fields[0]
n=fields[1]
D = int(d)
N = int(n)
print('d is:',D)
print('n is:',N)
decryptFile.close()
Decryption.decryption(D, N)
#reading cipher text file
def readCipherTextFile():
decryptFile = open('CipherTextFile.txt', 'r')
for line in decryptFile:
msg = line.split(",")
print('Cipher Text:', msg)
return msg
#decryption methd that use to decryt the cipher text in order to retreive the plain message
def decryption(d,n):
CipherText = Decryption.readCipherTextFile()
integerCode =[]
for i in range(0, len(CipherText)-1):
code = int(CipherText[i], 16)
integerCode.append(code)
print('Text:', integerCode)
text=[]
msg=[]
for i in range(0,len(integerCode)):
m=(integerCode[i]**d)%n
text.append(m)
plainText=chr(text[i])
msg.append(plainText)
#writing retrieved plain text msg in to the decrypted msg file
with open('DecryptedMsgFile.txt', 'a') as a:
a.write(plainText)
#print('Plian Text:',msg)
a.close()
def main():
Decryption.readDecryptKeyFile()
Decryption.main()