-
Notifications
You must be signed in to change notification settings - Fork 1
/
gui_zero.py
86 lines (69 loc) · 2.48 KB
/
gui_zero.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
from guizero import App, Text, PushButton, TextBox, Box, error
from tkinter.filedialog import askopenfilename, asksaveasfile
from png_stegano import FilterSteganographer
import string
input_path = None
buffer = None
def read_key():
try:
return int(key_input.get())
except:
return None
def choose_file():
global input_path, buffer
input_path = askopenfilename(
filetypes=(("PNG images", "*.png"), ("All Files", "*.*")),
title="Choose image"
)
if not input_path:
return
input_path_widget.set_text(input_path)
with open(input_path, 'rb') as f:
buffer = f.read()
hidden_data = FilterSteganographer().get(buffer, read_key())
hidden_data_text.set("Hidden data found: ")
if hidden_data and any(chr(byte) in string.printable for byte in hidden_data):
hidden_data_red_text.set(hidden_data)
else:
hidden_data_red_text.set('No data')
def save_file():
if not buffer:
error('Error', 'No file loaded!')
return
try:
buffer_with_data = FilterSteganographer().\
hide(buffer, bytes(text_box_secret.get(), encoding='utf8'), read_key())
except AssertionError as e:
error('Error', e)
return
f = asksaveasfile(mode='wb', defaultextension=".png")
if f is None: # asksaveasfile return `None` if dialog closed with "cancel".
return
f.write(buffer_with_data)
f.close()
app = App(title="Hello world", layout='auto', height=150)
vertical_box = Box(app, layout='grid')
horizontal_box0 = Box(vertical_box, layout='grid', grid=(0, 0))
horizontal_box1 = Box(vertical_box, layout='grid', grid=(1, 0))
horizontal_box2 = Box(vertical_box, layout='grid', grid=(2, 0))
horizontal_box3 = Box(vertical_box, layout='grid', grid=(3, 0))
horizontal_box4 = Box(vertical_box, layout='grid', grid=(4, 0))
input_path_widget = PushButton(
horizontal_box0,
text="Choose file...",
command=choose_file,
grid=(0, 0),
)
message_secret = Text(horizontal_box1, "Secret message: ", grid=(0, 0))
text_box_secret = TextBox(horizontal_box1, text='', width=20, grid=(0, 1))
save_file_widget = PushButton(
horizontal_box1,
text="Save stego-file...",
command=save_file,
grid=(0, 2)
)
hidden_data_text = Text(horizontal_box2, "", grid=(0, 0))
hidden_data_red_text = Text(horizontal_box2, "", grid=(0, 1), color='red')
key_inpu_text = Text(horizontal_box3, "Key: ", grid=(0, 0))
key_input = TextBox(horizontal_box3, "", grid=(0, 1))
app.display()