Skip to content

Commit ae68022

Browse files
author
Christian Bender
committed
fixed the decrypt-function and improved the code.
1 parent 53f312e commit ae68022

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

EncryptionTool.py

+16-16
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,41 @@
22
#Simple encryption script for text
33
#This was one my first versions of this script
44
#09/07/2017
5+
import math
56

67
text=input("Enter text: ")
7-
PI=3.14159265358979323846264338327950288419716939937510
8-
text=list(text)
9-
values= list()
10-
reverse=list()
8+
values= []
9+
reverse= []
1110
def encryptChar(target):
1211
#encrytion algorithm
13-
target=(((target+42)*PI)-449)
12+
target=(((target+42)*math.pi)-449)
1413
return target
1514

1615
def decryptChar(target):
17-
target=(((target+449)/PI)-42)
16+
target=(((target+449)/math.pi)-42)
1817
return target
1918

2019
def encrypt(input_text):
21-
input_text_list=list(input_text)
22-
col_values=list()
23-
for i in range (len(input_text_list)):
24-
current=ord(input_text_list[i])
20+
col_values= []
21+
for i in range (len(input_text)):
22+
current=ord(input_text[i])
2523
current=encryptChar(current)
2624
col_values.append(current)
2725
return col_values
2826

2927
def decrypt(enc_text):
30-
enc_list
31-
for i in range (len(input_text_list)):
32-
current=int(decryptChar(values[i]))
28+
col_values = []
29+
for i in range (len(enc_text)):
30+
current=int(decryptChar(enc_text[i]))
3331
current=chr(current)
3432
col_values.append(current)
3533
return col_values
3634

3735
def readAndDecrypt(filename):
3836
file=open(filename,"r")
3937
data=file.read()
40-
datalist=list()
41-
datalistint=list()
42-
actualdata=list()
38+
datalistint= []
39+
actualdata= []
4340
datalist=data.split(" ")
4441
datalist.remove('')
4542
for i in range(len(datalist)):
@@ -48,6 +45,7 @@ def readAndDecrypt(filename):
4845
current1=int(decryptChar(datalistint[i]))
4946
current1=chr(current1)
5047
actualdata.append(current1)
48+
file.close()
5149
return actualdata
5250

5351
def readAndEncrypt(filename):
@@ -60,6 +58,7 @@ def readAndEncrypt(filename):
6058
current=ord(datalist[i])
6159
current=encryptChar(current)
6260
encrypted_list.append(current)
61+
file.close()
6362
return encrypted_list
6463

6564
def readAndEncryptAndSave(inp_file,out_file):
@@ -75,6 +74,7 @@ def readAndDecryptAndSave(inp_file,out_file):
7574
for i in range(len(dec_list)):
7675
output.write(str(dec_list[i]))
7776
output.close()
77+
7878
#encryption
7979
for i in range (len(text)):
8080
current=ord(text[i])

0 commit comments

Comments
 (0)