|
| 1 | +#GGearing |
| 2 | +#Simple encryption script for text |
| 3 | +#This was one my first versions of this script |
| 4 | +#09/07/2017 |
| 5 | + |
| 6 | +text=input("Enter text: ") |
| 7 | +PI=3.14159265358979323846264338327950288419716939937510 |
| 8 | +text=list(text) |
| 9 | +values= list() |
| 10 | +reverse=list() |
| 11 | +def encryptChar(target): |
| 12 | + #encrytion algorithm |
| 13 | + target=(((target+42)*PI)-449) |
| 14 | + return target |
| 15 | + |
| 16 | +def decryptChar(target): |
| 17 | + target=(((target+449)/PI)-42) |
| 18 | + return target |
| 19 | + |
| 20 | +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]) |
| 25 | + current=encryptChar(current) |
| 26 | + col_values.append(current) |
| 27 | + return col_values |
| 28 | + |
| 29 | +def decrypt(enc_text): |
| 30 | + enc_list |
| 31 | + for i in range (len(input_text_list)): |
| 32 | + current=int(decryptChar(values[i])) |
| 33 | + current=chr(current) |
| 34 | + col_values.append(current) |
| 35 | + return col_values |
| 36 | + |
| 37 | +def readAndDecrypt(filename): |
| 38 | + file=open(filename,"r") |
| 39 | + data=file.read() |
| 40 | + datalist=list() |
| 41 | + datalistint=list() |
| 42 | + actualdata=list() |
| 43 | + datalist=data.split(" ") |
| 44 | + datalist.remove('') |
| 45 | + for i in range(len(datalist)): |
| 46 | + datalistint.append(float(datalist[i])) |
| 47 | + for i in range(len(datalist)): |
| 48 | + current1=int(decryptChar(datalistint[i])) |
| 49 | + current1=chr(current1) |
| 50 | + actualdata.append(current1) |
| 51 | + return actualdata |
| 52 | + |
| 53 | +def readAndEncrypt(filename): |
| 54 | + file=open(filename,"r") |
| 55 | + data=file.read() |
| 56 | + datalist=list(data) |
| 57 | + encrypted_list=list() |
| 58 | + encrypted_list_str=list() |
| 59 | + for i in range(len(datalist)): |
| 60 | + current=ord(datalist[i]) |
| 61 | + current=encryptChar(current) |
| 62 | + encrypted_list.append(current) |
| 63 | + return encrypted_list |
| 64 | + |
| 65 | +def readAndEncryptAndSave(inp_file,out_file): |
| 66 | + enc_list=readAndEncrypt(inp_file) |
| 67 | + output=open(out_file,"w") |
| 68 | + for i in range(len(enc_list)): |
| 69 | + output.write(str(enc_list[i])+" ") |
| 70 | + output.close() |
| 71 | + |
| 72 | +def readAndDecryptAndSave(inp_file,out_file): |
| 73 | + dec_list=readAndDecrypt(inp_file) |
| 74 | + output=open(out_file,"w") |
| 75 | + for i in range(len(dec_list)): |
| 76 | + output.write(str(dec_list[i])) |
| 77 | + output.close() |
| 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 | + |
0 commit comments