-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdecrypt.py
52 lines (37 loc) · 1.12 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
49
50
51
52
#!/usr/bin/env python3
# Import libraries
import os
from cryptography.fernet import Fernet
print("... libraries imported")
# Collect list of files
def get_file_list():
files = []
for file in os.listdir():
if file == "encrypt.py" or file == "decrypt.py" or file == "key_file.key":
continue
if os.path.isfile(file):
files.append(file)
print("Found files are:", files)
return files
# Get Key
def get_key():
with open("key_file.key", "rb") as f:
key = f.read()
print("...key found")
return key
# Decrypt
def decryption_process(files, key):
password = input("Enter the password to decrypt the files:")
if password == "ransome":
print("Decryption started...")
for file in files:
with open(file, "rb") as f:
content = f.read()
decrypted_content = Fernet(key).decrypt(content)
with open(file, "wb") as f:
f.write(decrypted_content)
print("...decryption complete")
# Main function calls
files = get_file_list()
key = get_key()
decryption_process(files, key)