-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencrypt.py
More file actions
60 lines (46 loc) · 1.41 KB
/
encrypt.py
File metadata and controls
60 lines (46 loc) · 1.41 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
from random import randint
import os.path
toEncrypt = input("Please enter the file you wish to encrypt: ")
while (not os.path.exists(toEncrypt)):
print("Whoops! That file doesn't seem to exist.")
toEncrypt = input("Please enter the file you wish to encrypt: ")
override = 0
while (override != '1'):
key = input("Please enter the desired name of the decryption key: ")
if (os.path.exists(key)):
print("It seems that this file already exists. Do you wish to overwrite it?")
override = input("'1' for overwrite | '0' to input new file name: ")
else:
override = str(1)
override = 0
while (override != '1'):
outFile = input("Please enter the desired name of the encrypted file: ")
if (os.path.exists(outFile)):
print("It seems that this file already exists. Do you wish to overwrite it?")
override = input("'1' for overwrite | '0' to input new file name: ")
else:
override = str(1)
inF = open(toEncrypt, "r")
inputFile = inF.readlines()
inF.close()
length = 0
for line in inputFile:
length += len(line)
inArr = []
for line in inputFile:
for i in range(len(line)):
inArr.append(int(ord(line[i])))
keyArr = []
for c in inArr:
keyArr.append(randint(32,126))
keyF = open(key, "w")
for c in keyArr:
keyF.write(chr(c))
keyF.close()
encrypted = []
for k in range(len(inArr)):
encrypted.append(str(inArr[k]^keyArr[k]))
encrypted = '|'.join(encrypted)
output = open(outFile, "w")
output.write(encrypted)
output.close()