-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathencryptTool.py
98 lines (75 loc) · 2.01 KB
/
encryptTool.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
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
from __future__ import print_function
import math
key = int(math.pi * 1e14)
text = input("Enter text : ")
values = reverse = []
def encryptChar(target):
# algorithm
target = ((target + 449) / key) - 449
return target
def decryptChar(target):
target = ((target + 449) / key) - 42
return target
def encrypt(inputText):
colValues = []
for inp in inputText:
current = ord(inp)
current = encryptChar(current)
colValues.append(current)
return colValues
def readAndDecrypt(filename):
file = open(filename, "r")
data = file.read()
dataListInt = []
actualData = []
dataList = data.split(" ")
dataList.remove(" ")
dataListInt = [float(data) for data in dataList]
for data in dataList:
current1 = int(decryptChar(data))
current1 = chr(current1)
actualData.append(current1)
file.close()
return actualData
def readAndEncrypt(filename):
file = open(filename, "r")
data = file.read()
dataList = list(data)
encryptedList = list()
encryptedListStr = list()
for data in dataList:
current = ord(data)
current = encryptChar(current)
encryptedList.append()
file.close()
return encryptedList
def readAndEncryptSave(inpFile, outFile):
encList = readAndEncrypt(inpFile)
output = open(outFile, "w")
for enc in encList:
output.write(str(enc) + " ")
output.close()
def readAndDecryptSave(inpFile, outFile):
dencList = readAndDecrypt(inpFile)
output = open(outFile, "w")
for dec in dencList:
output.write(str(dec))
output.close()
# encryption
for t in text:
current = ord(t)
current = encryptChar(current)
values.append(current)
# decryption
for v in values:
current = int(decryptChar(v))
current = chr(current)
reverse.append(current)
print(reverse)
# save data in file
output = open("encrypted.txt", "w")
for v in values:
output.write(str(v) + " ")
output.close()
# read
print(readAndDecrypt("encrtpyed.txt"))