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