forked from geekcomputers/Python
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEncryptionTool.py
More file actions
Latest commit
114 lines (90 loc) · 2.6 KB
/
Copy pathEncryptionTool.py
File metadata and controls
114 lines (90 loc) · 2.6 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# GGearing
# Simple encryption script for text
# This was one my first versions of this script
# 09/07/2017
from __future__ importprint_function
importmath
try:
input=raw_input
exceptNameError:
pass
key=int(math.pi*1e14)
text=input("Enter text: ")
values=reverse= []
defencryptChar(target):
# encrytion algorithm
target= (((target+42) *key) -449)
returntarget
defdecryptChar(target):
target= (((target+449) /key) -42)
returntarget
defencrypt(input_text):
col_values= []
foriinrange(len(input_text)):
current=ord(input_text[i])
current=encryptChar(current)
col_values.append(current)
returncol_values
defdecrypt(enc_text):
col_values= []
foriinrange(len(enc_text)):
current=int(decryptChar(enc_text[i]))
current=chr(current)
col_values.append(current)
returncol_values
defreadAndDecrypt(filename):
file=open(filename, "r")
data=file.read()
datalistint= []
actualdata= []
datalist=data.split(" ")
datalist.remove('')
datalistint= [float(datalist[i]) foriinrange(len(datalist))]
foriinrange(len(datalist)):
current1=int(decryptChar(datalistint[i]))
current1=chr(current1)
actualdata.append(current1)
file.close()
returnactualdata
defreadAndEncrypt(filename):
file=open(filename, "r")
data=file.read()
datalist=list(data)
encrypted_list=list()
encrypted_list_str=list()
foriinrange(len(datalist)):
current=ord(datalist[i])
current=encryptChar(current)
encrypted_list.append(current)
file.close()
returnencrypted_list
defreadAndEncryptAndSave(inp_file, out_file):
enc_list=readAndEncrypt(inp_file)
output=open(out_file, "w")
foriinrange(len(enc_list)):
output.write(str(enc_list[i]) +" ")
output.close()
defreadAndDecryptAndSave(inp_file, out_file):
dec_list=readAndDecrypt(inp_file)
output=open(out_file, "w")
foriinrange(len(dec_list)):
output.write(str(dec_list[i]))
output.close()
# encryption
foriinrange(len(text)):
current=ord(text[i])
current=encryptChar(current)
values.append(current)
# decryption
foriinrange(len(text)):
current=int(decryptChar(values[i]))
current=chr(current)
reverse.append(current)
print(reverse)
# saves encrypted in txt file
output=open("encrypted.txt", "w")
foriinrange(len(values)):
output.write(str(values[i]) +" ")
output.close()
# read and decrypts
print(readAndDecrypt("encrypted.txt"))