-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEncryption .py
More file actions
81 lines (54 loc) · 1.91 KB
/
Copy pathEncryption .py
File metadata and controls
81 lines (54 loc) · 1.91 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
69
70
71
72
73
74
75
76
77
78
79
# coding: utf-8
class Encryption:
#reading encryption key file
def readEncryptionKeyFile():
Encryptfile = open('EncryptionKeyFile.txt', 'r')
for line in Encryptfile:
fields = line.split(",")
e=fields[0]
n=fields[1]
E = int(e)
N = int(n)
print('e is:',E)
print('n is:',N)
Encryption.encryption(E, N)
#reading plainText file
def readPlainTextFile():
plainFile = open('plainTextFile.txt', 'r')
for line in plainFile:
msg = line.split()
print('Plain Text Message:',msg)
numbers=[]
msgSet=[]
for i in range (0,len(msg)):
intMSG = msg[i]
for j in range (0,len(intMSG)):
numbers = list(intMSG)
msgSet.append(numbers[j])
print('Plain Text Array:',msgSet)
plainFile.close()
return msgSet
#Encryption method is use to encryt the plain text
def encryption(e,n):
message = Encryption.readPlainTextFile()
intCode =[]
for i in range(0, len(message)):
cd=hex(ord(message[i]))
intCode.append(cd)
cipher=[]
text=[]
for i in range(0,len(intCode)):
#calculation of the encryted value
c = (int(intCode[i],16)**e)%n
cipher.append(hex(c))
cipherText = str(cipher[i])
text.append(cipherText)
#Writing cipher text in to the cipher text file
with open('CipherTextFile.txt', 'a') as a:
a.write(cipherText)
a.write(",")
a.close()
print('Cipher Text:',text)
def main():
Encryption.readEncryptionKeyFile()
Encryption.main()