-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
38 lines (37 loc) · 1.4 KB
/
main.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
from PIL import Image
import decrypt
import encrypt
import sys
import re
if __name__ == '__main__':
filename = input('Filename?')
operation = input('Encrypt or Decrypt?')
passwd = input('Password?')
if not len(passwd) == 16:
raise Warning('密码长度错误,请输入长度为16的密码!', len(passwd))
if operation == 'encrypt':
try:
with open(filename, encoding='utf-8') as f:
try:
img = encrypt.encrypt(f, passwd)['img']
passwd_img = encrypt.encrypt(f, passwd)['passwd_img']
img.save(filename + '.png')
passwd_img.save(filename + '_passwd.png')
except:
print('Failed!')
except:
print('Failed!')
elif operation == 'decrypt':
passwd_filename = re.sub('.png$', '_passwd.png', filename)
try:
text = decrypt.decrypt(Image.open(filename, 'r'), Image.open(
passwd_filename, 'r'), passwd)['content']
if decrypt.decrypt(Image.open(filename, 'r'), Image.open(passwd_filename, 'r'), passwd)['success'] == 'yes':
with open(filename + '.txt', 'w', encoding='utf-8') as f:
f.write(text)
else:
print('Failed!')
except:
print('Failed!')
else:
sys.exit()