|
1 |
| -#GGearing |
2 |
| -#Simple encryption script for text |
3 |
| -#This was one my first versions of this script |
4 |
| -#09/07/2017 |
| 1 | +# GGearing |
| 2 | +# Simple encryption script for text |
| 3 | +# This was one my first versions of this script |
| 4 | +# 09/07/2017 |
5 | 5 | from __future__ import print_function
|
6 | 6 | import math
|
7 | 7 | import sys
|
|
15 | 15 | else:
|
16 | 16 | input_fun = raw_input
|
17 | 17 |
|
18 |
| -text=input_fun("Enter text: ") |
19 |
| -values= [] |
20 |
| -reverse= [] |
| 18 | +text = input_fun("Enter text: ") |
| 19 | +values = [] |
| 20 | +reverse = [] |
| 21 | + |
| 22 | + |
21 | 23 | def encryptChar(target):
|
22 |
| - #encrytion algorithm |
23 |
| - target=(((target+42) * key) -449) |
| 24 | + # encrytion algorithm |
| 25 | + target = (((target + 42) * key) - 449) |
24 | 26 | return target
|
25 | 27 |
|
| 28 | + |
26 | 29 | def decryptChar(target):
|
27 |
| - target=(((target+449) / key) -42) |
| 30 | + target = (((target + 449) / key) - 42) |
28 | 31 | return target
|
29 | 32 |
|
| 33 | + |
30 | 34 | def encrypt(input_text):
|
31 |
| - col_values= [] |
32 |
| - for i in range (len(input_text)): |
33 |
| - current=ord(input_text[i]) |
34 |
| - current=encryptChar(current) |
| 35 | + col_values = [] |
| 36 | + for i in range(len(input_text)): |
| 37 | + current = ord(input_text[i]) |
| 38 | + current = encryptChar(current) |
35 | 39 | col_values.append(current)
|
36 | 40 | return col_values
|
37 | 41 |
|
| 42 | + |
38 | 43 | def decrypt(enc_text):
|
39 | 44 | col_values = []
|
40 |
| - for i in range (len(enc_text)): |
41 |
| - current=int(decryptChar(enc_text[i])) |
42 |
| - current=chr(current) |
| 45 | + for i in range(len(enc_text)): |
| 46 | + current = int(decryptChar(enc_text[i])) |
| 47 | + current = chr(current) |
43 | 48 | col_values.append(current)
|
44 | 49 | return col_values
|
45 | 50 |
|
| 51 | + |
46 | 52 | def readAndDecrypt(filename):
|
47 |
| - file=open(filename,"r") |
48 |
| - data=file.read() |
49 |
| - datalistint= [] |
50 |
| - actualdata= [] |
51 |
| - datalist=data.split(" ") |
| 53 | + file = open(filename, "r") |
| 54 | + data = file.read() |
| 55 | + datalistint = [] |
| 56 | + actualdata = [] |
| 57 | + datalist = data.split(" ") |
52 | 58 | datalist.remove('')
|
53 | 59 | for i in range(len(datalist)):
|
54 | 60 | datalistint.append(float(datalist[i]))
|
55 | 61 | for i in range(len(datalist)):
|
56 |
| - current1=int(decryptChar(datalistint[i])) |
57 |
| - current1=chr(current1) |
| 62 | + current1 = int(decryptChar(datalistint[i])) |
| 63 | + current1 = chr(current1) |
58 | 64 | actualdata.append(current1)
|
59 | 65 | file.close()
|
60 | 66 | return actualdata
|
61 | 67 |
|
| 68 | + |
62 | 69 | def readAndEncrypt(filename):
|
63 |
| - file=open(filename,"r") |
64 |
| - data=file.read() |
65 |
| - datalist=list(data) |
66 |
| - encrypted_list=list() |
67 |
| - encrypted_list_str=list() |
| 70 | + file = open(filename, "r") |
| 71 | + data = file.read() |
| 72 | + datalist = list(data) |
| 73 | + encrypted_list = list() |
| 74 | + encrypted_list_str = list() |
68 | 75 | for i in range(len(datalist)):
|
69 |
| - current=ord(datalist[i]) |
70 |
| - current=encryptChar(current) |
| 76 | + current = ord(datalist[i]) |
| 77 | + current = encryptChar(current) |
71 | 78 | encrypted_list.append(current)
|
72 | 79 | file.close()
|
73 | 80 | return encrypted_list
|
74 | 81 |
|
75 |
| -def readAndEncryptAndSave(inp_file,out_file): |
76 |
| - enc_list=readAndEncrypt(inp_file) |
77 |
| - output=open(out_file,"w") |
| 82 | + |
| 83 | +def readAndEncryptAndSave(inp_file, out_file): |
| 84 | + enc_list = readAndEncrypt(inp_file) |
| 85 | + output = open(out_file, "w") |
78 | 86 | for i in range(len(enc_list)):
|
79 |
| - output.write(str(enc_list[i])+" ") |
| 87 | + output.write(str(enc_list[i]) + " ") |
80 | 88 | output.close()
|
81 | 89 |
|
82 |
| -def readAndDecryptAndSave(inp_file,out_file): |
83 |
| - dec_list=readAndDecrypt(inp_file) |
84 |
| - output=open(out_file,"w") |
| 90 | + |
| 91 | +def readAndDecryptAndSave(inp_file, out_file): |
| 92 | + dec_list = readAndDecrypt(inp_file) |
| 93 | + output = open(out_file, "w") |
85 | 94 | for i in range(len(dec_list)):
|
86 | 95 | output.write(str(dec_list[i]))
|
87 | 96 | output.close()
|
88 | 97 |
|
89 |
| -#encryption |
90 |
| -for i in range (len(text)): |
91 |
| - current=ord(text[i]) |
92 |
| - current=encryptChar(current) |
| 98 | + |
| 99 | +# encryption |
| 100 | +for i in range(len(text)): |
| 101 | + current = ord(text[i]) |
| 102 | + current = encryptChar(current) |
93 | 103 | values.append(current)
|
94 | 104 |
|
95 |
| -#decryption |
96 |
| -for i in range (len(text)): |
97 |
| - current=int(decryptChar(values[i])) |
98 |
| - current=chr(current) |
| 105 | +# decryption |
| 106 | +for i in range(len(text)): |
| 107 | + current = int(decryptChar(values[i])) |
| 108 | + current = chr(current) |
99 | 109 | reverse.append(current)
|
100 | 110 | print(reverse)
|
101 | 111 |
|
102 |
| -#saves encrypted in txt file |
103 |
| -output=open("encrypted.txt","w") |
| 112 | +# saves encrypted in txt file |
| 113 | +output = open("encrypted.txt", "w") |
104 | 114 | for i in range(len(values)):
|
105 |
| - output.write(str(values[i])+" ") |
| 115 | + output.write(str(values[i]) + " ") |
106 | 116 | output.close()
|
107 | 117 |
|
108 |
| -#read and decrypts |
| 118 | +# read and decrypts |
109 | 119 | print(readAndDecrypt("encrypted.txt"))
|
110 |
| - |
111 |
| - |
|
0 commit comments