-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencrypt.py
More file actions
79 lines (59 loc) · 1.9 KB
/
encrypt.py
File metadata and controls
79 lines (59 loc) · 1.9 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import random
import array
def Encrypt(filename, key):
file = open(filename, "rb")
data = file.read()
file.close()
data = bytearray(data)
for index, value in enumerate(data):
data[index] = value ^ key
max_len = 14
number = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
low = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
'i', 'j', 'k', 'm', 'n', 'o', 'p', 'q',
'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
'z']
up = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
'I', 'J', 'K', 'M', 'N', 'O', 'P', 'Q',
'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y',
'Z']
combine = number + up + low
n = random.choice(number)
u = random.choice(up)
l = random.choice(low)
core = n + u + l
for x in range(max_len - 4):
core = core + random.choice(combine)
lists = array.array('u', core)
random.shuffle(lists)
generate = ""
for x in lists:
generate = generate + x
file = open(generate + filename, "wb")
file.write(data)
file.close()
def Decrypt(filename, key):
file = open(filename, "rb")
data = file.read()
file.close()
data = bytearray(data)
for index, value in enumerate(data):
data[index] = value ^ key
file = open(filename, "wb")
file.write(data)
file.close()
choice = ""
while choice != "3":
print("Please select you option.")
print("1. Encrypt File")
print("2. Decrypt File")
print("3. Quit")
choice = input()
match choice:
case '1' | '2':
key = int(input("Enter password as int: \n"))
filename = input("Enter file with extension: \n")
case '1':
Encrypt(filename, key)
case '2':
Decrypt(filename, key)