-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecrypting.py
44 lines (35 loc) · 1.35 KB
/
decrypting.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 pyAesCrypt
import os
import sys
def decrypt_file(file_path, password, buffer_size=512 * 1024):
"""
Decrypt a file using the specified password.
The decrypted file will have the same name as the original, without the '.crp' extension.
"""
try:
# Decrypt the file
pyAesCrypt.decryptFile(file_path, file_path[:-4], password, buffer_size)
# Print the name of the decrypted file
print("File '{}' decrypted.".format(os.path.basename(file_path)[:-4]))
# Delete the encrypted file
os.remove(file_path)
except Exception as e:
print("Error decrypting file: ", e)
def decrypt_directory(directory, password, buffer_size=512 * 1024):
"""
Recursively walk through the specified directory and decrypt all '.crp' files found.
"""
for name in os.listdir(directory):
path = os.path.join(directory, name)
if os.path.isfile(path) and path.endswith('.crp'):
decrypt_file(path, password, buffer_size)
elif os.path.isdir(path):
decrypt_directory(path, password, buffer_size)
def main():
# Input directory
directory = input("Enter the directory path to decrypt: ")
password = input("Enter the password for decryption: ")
decrypt_directory(directory, password)
# os.remove(str(sys.argv[0]))
if __name__ == '__main__':
main()