-
Notifications
You must be signed in to change notification settings - Fork 0
/
decrypt.py
48 lines (36 loc) · 1.16 KB
/
decrypt.py
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
import os
from utilities import decrypt, generate_key
excluded_dirs = {"env", ".git"}
excluded_files = {
"decrypt.py",
"test.py",
"encrypt.py",
"utilities.py",
"key.txt",
"README.md",
".gitignore",
}
files = []
# TODO: change this dir to the home for the current user
for root, dirs, filenames in os.walk("/Users/noetrevino/Desktop/"):
dirs[:] = [d for d in dirs if d not in excluded_dirs]
for file in filenames:
if file in excluded_files:
continue
files.append(os.path.join(root, file))
print("Files to decrypt:", files)
# enter the pass in the decryption file
password: bytes = input("enter password: ").encode() # str -> binary
# enter the salt in the decryption file
salt: bytes = input("enter salt: ").encode()
secret_key = generate_key(password, salt)
# print("\n", "secret key: ",secret_key)
# TODO: remove this
print("\n", "generated Secret Key:", secret_key)
for file in files:
with open(file, "rb") as _file:
contents = _file.read()
dec_content = decrypt(secret_key, contents)
with open(file, "wb") as _file:
_file.write(dec_content)
print("decryption successful")