
20.08.2021, 18:42
|
|
Участник форума
Регистрация: 17.04.2020
Сообщений: 184
С нами:
3197792
Репутация:
83
|
|
Идею взял отсюда - PythonToday.
Одел в более-менее приятный Tkinter интерфейс.
Шифрует файлы любого расширения.
При вводе ключа, который кстати необходимо куда-нибудь записать/запомнить, создаётся папка main в папке с исполняемым файлом. В эту папку кидаем файлы которые хотим зашифровать. (Для особо ленивых есть функция open, чтобы открыть эту папку.) В программе жмём encrypt и наблюдаем. Все файлы с расширением ... .crp - зашифрованы, их сможете открыть только вы, т.к только вы знаете код, который ввели вначале.
Ошибок у программы никаких быть не может (Windows 10), код обкатан на 3-ёх компах.
Зависимости:
pyAesCrypt
Работа только от имени администратора.
Любая попытка контакта с создаваемыми скриптом файлами приведёт к удалению всех файлов в папке main, если работать так, как показано на видео - ничего не удалиться.
1) Не пытайтесь менять расширения закриптованных файлов, в противном случае придётся вернуть старое чтобы снова открыть файл после Decrypt.
2) Не пытайтесь удалить папку Burn The Dark в Program files, или же удалять файл cfg.crp в этой папке. Это приведёт к удалению всех файлов связанных с программой, и всех файлов в папке main.
3) Для компиляции используйте pyarmor либо pyinstaller. (желательно pyarmor).
4) Не нужно пихать в программу 50 ГБ игры/видео, а потом писать сюда что очень долго.
Работоспособность:
Сообщение от Спойлер
main.py:
Код:
import
tkinter
import
time
import
json
import
datetime
import
os
import
pyAesCrypt
import
shutil
import
subprocess
import
sys
import
config
from
tkinter
import
Button
,
Entry
,
messagebox
,
Label
,
PhotoImage
from
crypt
import
*
from
other_funcs
import
*
class
Window
(
)
:
"""Main window"""
def
__init__
(
self
,
title_
,
icon
,
width
=
500
,
height
=
275
)
:
self
.
root
=
tkinter
.
Tk
(
)
self
.
root
.
geometry
(
f'{width}x{height}'
)
self
.
root
.
resizable
(
False
,
False
)
self
.
root
.
title
(
title_
)
self
.
root
[
'bg'
]
=
config
.
backgrond_color
""" Empty Label """
self
.
empty_label
=
Label
(
self
.
root
,
background
=
config
.
backgrond_color
)
self
.
empty_label
.
pack
(
**
config
.
upper_empty_label_padding
)
try
:
""" Icon """
self
.
root
.
iconbitmap
(
icon
)
""" Background image """
self
.
image
=
PhotoImage
(
file
=
config
.
background_path
)
self
.
label_image
=
Label
(
self
.
root
,
borderwidth
=
0
)
self
.
label_image
.
image
=
self
.
image
self
.
label_image
[
'image'
]
=
self
.
label_image
.
image
self
.
label_image
.
place
(
x
=
0
,
y
=
0
)
except
Exception
as
error
:
crashlog
(
error
)
def
start
(
self
)
:
self
.
root
.
mainloop
(
)
def
register_button
(
self
)
:
password
=
self
.
entry_password
.
get
(
)
if
not
password
:
messagebox
.
showwarning
(
'Warning.'
,
'The key field is empty.'
)
else
:
""" Make first-registration folder """
mkdir
(
)
mkcfg
(
)
encryption
(
config
.
cfg_path
,
password
)
messagebox
.
showinfo
(
'Success'
,
'Restart a program.'
)
sys
.
exit
(
)
def
after_success_login
(
self
)
:
""" Remove login startup """
self
.
label_nothing
.
destroy
(
)
self
.
label_password
.
destroy
(
)
self
.
entry_password
.
destroy
(
)
self
.
button_login
.
destroy
(
)
""" Call main menu function """
window
.
main_menu
(
)
def
check_login
(
self
)
:
global
password
password
=
self
.
entry_password
.
get
(
)
try
:
decryption
(
config
.
cfg_path
+
'.crp'
,
password
)
encryption
(
config
.
cfg_path
,
password
)
window
.
after_success_login
(
)
except
Exception
as
error
:
messagebox
.
showwarning
(
'Error'
,
'Wrong password.'
)
def
login
(
self
)
:
self
.
label_nothing
=
Label
(
self
.
root
,
text
=
''
,
background
=
config
.
backgrond_color
,
)
""" Label """
self
.
label_password
=
Label
(
self
.
root
,
text
=
'Key'
,
background
=
config
.
backgrond_color
,
foreground
=
config
.
labels_color
,
font
=
config
.
labels_font
,
)
""" Entry """
self
.
entry_password
=
Entry
(
self
.
root
,
font
=
config
.
entries_font
,
relief
=
'flat'
,
foreground
=
config
.
labels_color
,
background
=
config
.
entry_color
,
show
=
config
.
symbol_password
)
""" Button """
self
.
button_login
=
Button
(
self
.
root
,
text
=
'Login'
,
font
=
config
.
buttons_font
,
relief
=
'flat'
,
background
=
config
.
buttons_color
,
activebackground
=
config
.
buttons_color
,
command
=
lambda
:
window
.
check_login
(
)
)
""" Packing """
self
.
label_nothing
.
pack
(
**
config
.
labels_padding
)
self
.
label_password
.
pack
(
)
self
.
entry_password
.
pack
(
)
self
.
button_login
.
pack
(
**
config
.
buttons_padding
)
def
registration
(
self
)
:
""" Upper label """
self
.
label_registration
=
Label
(
self
.
root
,
text
=
'Welcome!\nEnter a new key to register'
,
font
=
config
.
welcome_font
,
background
=
config
.
backgrond_color
,
foreground
=
config
.
welcome_labels_color
)
""" Register label """
self
.
label_password
=
Label
(
self
.
root
,
text
=
'Key'
,
background
=
config
.
backgrond_color
,
foreground
=
config
.
labels_color
,
font
=
config
.
labels_font
,
)
""" Register entry """
self
.
entry_password
=
Entry
(
self
.
root
,
font
=
config
.
entries_font
,
relief
=
'flat'
,
foreground
=
config
.
labels_color
,
background
=
config
.
entry_color
,
show
=
config
.
symbol_password
)
""" Register button """
self
.
button_register
=
Button
(
self
.
root
,
text
=
'Register'
,
font
=
config
.
buttons_font
,
relief
=
'flat'
,
background
=
config
.
buttons_color
,
activebackground
=
config
.
buttons_color
,
command
=
lambda
:
window
.
register_button
(
)
)
""" Packing """
self
.
label_registration
.
pack
(
**
config
.
labels_padding
)
self
.
label_password
.
pack
(
)
self
.
entry_password
.
pack
(
)
self
.
button_register
.
pack
(
**
config
.
buttons_padding
)
def
main_menu
(
self
)
:
""" After success login you get it """
self
.
button_open
=
Button
(
self
.
root
,
text
=
'Open'
,
font
=
config
.
buttons_font
,
relief
=
'flat'
,
background
=
config
.
buttons_color
,
activebackground
=
config
.
buttons_color
,
width
=
config
.
width_buttons
,
command
=
open_directory
)
self
.
button_destroy
=
Button
(
self
.
root
,
text
=
'Destroy'
,
font
=
config
.
buttons_font
,
relief
=
'flat'
,
background
=
config
.
buttons_color
,
activebackground
=
config
.
buttons_color
,
width
=
config
.
width_buttons
,
command
=
destroy
)
self
.
button_encrypt
=
Button
(
self
.
root
,
text
=
'Encrypt'
,
font
=
config
.
buttons_font
,
relief
=
'flat'
,
background
=
config
.
buttons_color
,
activebackground
=
config
.
buttons_color
,
width
=
config
.
width_buttons
,
command
=
lambda
:
walking_by_dirs_encryption
(
config
.
main_folder_path
,
password
)
)
self
.
button_decrypt
=
Button
(
self
.
root
,
text
=
'Decrypt'
,
font
=
config
.
buttons_font
,
relief
=
'flat'
,
background
=
config
.
buttons_color
,
activebackground
=
config
.
buttons_color
,
width
=
config
.
width_buttons
,
command
=
lambda
:
walking_by_dirs_decryption
(
config
.
main_folder_path
,
password
)
)
""" Packing """
self
.
button_open
.
pack
(
**
config
.
main_menu_padding
)
self
.
button_destroy
.
pack
(
**
config
.
main_menu_padding
)
self
.
button_encrypt
.
pack
(
**
config
.
main_menu_padding
)
self
.
button_decrypt
.
pack
(
**
config
.
main_menu_padding
)
if
__name__
==
'__main__'
:
window
=
Window
(
title_
=
config
.
title_
,
icon
=
config
.
icon_path
)
start
=
check_registration
(
)
if
start
==
1
:
window
.
login
(
)
window
.
start
(
)
else
:
window
.
registration
(
)
window
.
start
(
)
other_funcs.py:
Код:
import
datetime
,
os
,
shutil
,
sys
,
config
from
tkinter
import
messagebox
import
subprocess
def
now_time
(
)
:
now
=
datetime
.
datetime
.
now
(
)
time
=
now
.
strftime
(
'%Y-%m-%d %H:%M:%S'
)
return
time
def
crashlog
(
error
)
:
time
=
now_time
(
)
time
=
f'[{time}]'
error
=
f'\n{str(error)}\n\n'
with
open
(
'crashlog.txt'
,
'a'
)
as
file
:
file
.
write
(
time
)
file
.
write
(
error
)
def
mkdir
(
)
:
os
.
mkdir
(
config
.
main_folder_path
)
os
.
mkdir
(
config
.
cfg_folder_path
)
subprocess
.
call
(
[
'attrib'
,
'+h'
,
config
.
cfg_folder_path
]
)
### Make folder hide ###
def
mkcfg
(
)
:
with
open
(
config
.
cfg_path
,
'w'
)
as
file
:
pass
def
check_registration
(
)
:
if
os
.
path
.
exists
(
config
.
cfg_path
+
'.crp'
)
:
if
not
os
.
path
.
exists
(
config
.
main_folder_path
)
:
os
.
mkdir
(
config
.
main_folder_path
)
return
1
else
:
if
not
os
.
path
.
exists
(
config
.
cfg_folder_path
)
:
try
:
shutil
.
rmtree
(
config
.
main_folder_path
)
except
Exception
as
error
:
crashlog
(
error
)
if
not
os
.
path
.
exists
(
config
.
cfg_path
+
'.crp'
)
:
try
:
shutil
.
rmtree
(
config
.
cfg_folder_path
)
shutil
.
rmtree
(
config
.
main_folder_path
)
except
Exception
as
error
:
crashlog
(
error
)
return
-
1
def
open_directory
(
)
:
os
.
startfile
(
config
.
main_folder_path
)
def
destroy
(
)
:
ask
=
messagebox
.
askokcancel
(
'Destroy'
,
'Are you sure that you want to permanently delete all files?'
)
if
ask
==
True
:
try
:
shutil
.
rmtree
(
config
.
cfg_folder_path
)
except
:
pass
try
:
shutil
.
rmtree
(
config
.
main_folder_path
)
except
:
pass
try
:
os
.
remove
(
'crashlog.txt'
)
except
:
pass
sys
.
exit
(
)
config.py:
Код:
""" Tkinter settings """
icon_path
=
'images/icon.ico'
background_path
=
'images/background.png'
cfg_path
=
'C:/Program Files/Burn The Dark/cfg'
cfg_folder_path
=
'C:/Program Files/Burn The Dark'
main_folder_path
=
'main'
title_
=
'BURN THE DARK'
""" Colors """
backgrond_color
=
'#141414'
entry_color
=
'#363636'
welcome_labels_color
=
'#607D5E'
labels_color
=
'#A0FF99'
buttons_color
=
'#7A7A7A'
""" Fonts """
welcome_font
=
(
'MADE Likes Slab'
,
15
)
buttons_font
=
(
'Bahnschrift'
,
12
)
labels_font
=
(
'Palatino Linotype'
,
12
)
entries_font
=
(
"Calibri 10"
)
"""Paddigns"""
upper_empty_label_padding
=
{
'padx'
:
0
,
'pady'
:
10
}
labels_padding
=
{
'padx'
:
0
,
'pady'
:
12
}
buttons_padding
=
{
'padx'
:
0
,
'pady'
:
5
}
main_menu_padding
=
{
'padx'
:
0
,
'pady'
:
8
}
""" Encryption/Decryption """
buffer_size
=
512
*
1024
""" Sybmols """
symbol_password
=
'▬'
""" Sizes """
width_buttons
=
10
crypt.py:
Код:
import
os
,
pyAesCrypt
,
config
def
encryption
(
file_path
,
password
)
:
buffer_
=
config
.
buffer_size
pyAesCrypt
.
encryptFile
(
str
(
file_path
)
,
str
(
file_path
)
+
".crp"
,
password
,
buffer_
)
os
.
remove
(
file_path
)
def
decryption
(
file_path
,
password
)
:
buffer_
=
config
.
buffer_size
pyAesCrypt
.
decryptFile
(
str
(
file_path
)
,
str
(
os
.
path
.
splitext
(
file_path
)
[
0
]
)
,
password
,
buffer_
)
os
.
remove
(
file_path
)
def
walking_by_dirs_decryption
(
dir
,
password
)
:
for
name
in
os
.
listdir
(
dir
)
:
path
=
os
.
path
.
join
(
dir
,
name
)
if
os
.
path
.
isfile
(
path
)
:
try
:
decryption
(
path
,
password
)
except
:
pass
else
:
walking_by_dirs_decryption
(
path
,
password
)
def
walking_by_dirs_encryption
(
dir
,
password
)
:
for
name
in
os
.
listdir
(
dir
)
:
path
=
os
.
path
.
join
(
dir
,
name
)
if
os
.
path
.
isfile
(
path
)
:
try
:
encryption
(
path
,
password
)
except
:
pass
else
:
walking_by_dirs_encryption
(
path
,
password
)
|
|
|
|
|
Здесь присутствуют: 1 (пользователей: 0 , гостей: 1)
|
|
|
|