-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
208 lines (146 loc) · 6.63 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
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
import threading
import time
from playsound import playsound
from customtkinter import *
from tkinterdnd2 import TkinterDnD, DND_ALL
from tkinter.filedialog import askopenfilename, asksaveasfilename
from tkinter.messagebox import showerror
from stegano import lsb
set_appearance_mode("dark")
set_default_color_theme("FlipperZeroTheme.json")
class Tk(CTk, TkinterDnD.DnDWrapper):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.TkdndVersion = TkinterDnD._require(self)
def show_error():
showerror("ERROR", "Expected a PNG image but received another file")
def process_drag_and_drop(event):
if event.data.endswith(".png") or event.data.endswith(".PNG"):
playsound('Sound.mp3', False)
encode_or_decode(event.data)
else:
show_error()
FILE = None
progressbar = None
img = None
frame = None
def encode_img(text):
global progressbar, img
img = lsb.hide(FILE, text)
progressbar.stop()
for x in range(0, 101):
progressbar.set(x/100)
root.update()
playsound('Sound.mp3', False)
time.sleep(0.5)
for widget in frame.winfo_children():
widget.destroy()
save_btn = CTkButton(frame, text="Click Here to Download the Image", font=("HaxrCorp4089", 70), command=save)
save_btn.place(anchor="center", relx=0.5, rely=0.5)
go_back = CTkButton(frame, text="< Go Back", font=("HaxrCorp4089", 70), command=home)
go_back.place(anchor="nw", x=20, y=20)
save()
def save():
file = asksaveasfilename()
if file != "":
if file.endswith(".png"):
img.save(file)
else:
img.save(file+".png")
def encode(text):
global progressbar
for widget in frame.winfo_children():
widget.destroy()
description = CTkLabel(frame, text="Working On It.....", font=("HaxrCorp4089", 50), anchor="w")
description.pack(fill="x", pady=20, padx=20)
progressbar = CTkProgressBar(frame, height=50, corner_radius=3)
progressbar.pack(expand=True, fill="x", padx=20)
progressbar.start()
t1 = threading.Thread(target=encode_img, args=(text, ))
t1.start()
def encode_ui():
playsound('Sound.mp3', False)
for widget in frame.winfo_children():
widget.destroy()
data = CTkTextbox(frame, height=300, font=("HaxrCorp4089", 50))
data.pack(expand=True, fill="both", padx=20, pady=20)
encode_btn = CTkButton(frame, font=("HaxrCorp4089", 70), text=" Encode", anchor="w", command=lambda : encode(data.get(0.0, "end")))
encode_btn.pack(expand=True, fill="both", padx=20, pady=(0, 20))
def decode_ui():
playsound('Sound.mp3', False)
for widget in frame.winfo_children():
widget.destroy()
try:
data = lsb.reveal(FILE)
text = CTkLabel(frame, text=data, font=("HaxrCorp4089", 70), wraplength=700, fg_color="transparent", bg_color="transparent")
text.place(anchor="center", relx=0.5, rely=0.5)
go_back = CTkButton(frame, text="< Go Back", font=("HaxrCorp4089", 70), command=home)
go_back.place(anchor="nw", x=20, y=20)
except Exception as e:
showerror("Error", e)
go_back = CTkButton(frame, text="< Go Back", font=("HaxrCorp4089", 70), command=home)
go_back.place(anchor="nw", x=20, y=20)
def encode_or_decode(file):
global FILE
playsound('Sound.mp3', False)
for widget in frame.winfo_children():
widget.destroy()
FILE = file
encodeOption = CTkFrame(frame)
encodeOption.pack(padx=20, pady=30, expand=True, fill="both", side="left")
encodeOption.bind("<Enter>", lambda e: encodeOption.configure(fg_color="#814007"))
encodeOption.bind("<Leave>", lambda e: encodeOption.configure(fg_color="#000000"))
encodeOption.bind("<Button-1>", lambda e: encode_ui())
description = CTkLabel(encodeOption, text="Add data to the image ", font=("HaxrCorp4089", 50), anchor="w")
description.pack(side="bottom", fill="x", pady=20, padx=20)
description.bind("<Enter>", lambda e: encodeOption.configure(fg_color="#814007"))
description.bind("<Leave>", lambda e: encodeOption.configure(fg_color="#000000"))
description.bind("<Button-1>", lambda e: encode_ui())
title = CTkLabel(encodeOption, text="Encode", font=("HaxrCorp4089", 70), anchor="w")
title.pack(side="bottom", fill="x", pady=0, padx=20)
title.bind("<Enter>", lambda e: encodeOption.configure(fg_color="#814007"))
title.bind("<Leave>", lambda e: encodeOption.configure(fg_color="#000000"))
title.bind("<Button-1>", lambda e: encode_ui())
decodeOption = CTkFrame(frame)
decodeOption.pack(padx=20, pady=30, expand=True, fill="both", side="left")
decodeOption.bind("<Enter>", lambda e: decodeOption.configure(fg_color="#814007"))
decodeOption.bind("<Leave>", lambda e: decodeOption.configure(fg_color="#000000"))
decodeOption.bind("<Button-1>", lambda e: decode_ui())
description = CTkLabel(decodeOption, text="Decode data in the image", font=("HaxrCorp4089", 50), anchor="w")
description.pack(side="bottom", fill="x", pady=20, padx=20)
description.bind("<Enter>", lambda e: decodeOption.configure(fg_color="#814007"))
description.bind("<Leave>", lambda e: decodeOption.configure(fg_color="#000000"))
description.bind("<Button-1>", lambda e: decode_ui())
title = CTkLabel(decodeOption, text="Decode", font=("HaxrCorp4089", 70), anchor="w")
title.pack(side="bottom", fill="x", pady=0, padx=20)
title.bind("<Enter>", lambda e: decodeOption.configure(fg_color="#814007"))
title.bind("<Leave>", lambda e: decodeOption.configure(fg_color="#000000"))
title.bind("<Button-1>", lambda e: decode_ui())
def choose_file():
file = askopenfilename()
if file != "":
if file.endswith(".png") or file.endswith(".PNG"):
playsound('Sound.mp3', False)
encode_or_decode(file)
else:
show_error()
root = Tk()
root.geometry("900x500")
root.title("Hide Data")
def home():
global frame
if frame != None:
frame.destroy()
playsound('Sound.mp3', False)
frame = CTkFrame(root)
frame.pack(padx=20, pady=20, expand=True, fill="both")
text = CTkLabel(frame, text="Drag and Drop the Image or Choose the File", font=("HaxrCorp4089", 50))
text.pack(pady=20)
dnd_frame = CTkFrame(frame)
dnd_frame.pack(padx=30, pady=(10, 30), expand=True, fill="both")
dnd_frame.drop_target_register(DND_ALL)
dnd_frame.dnd_bind("<<Drop>>", process_drag_and_drop)
lbl = CTkButton(dnd_frame, text="Click to choose the file or Drag and Drop the File", font=("HaxrCorp4089", 30), hover=False, fg_color="transparent", command=choose_file)
lbl.pack(expand=True, fill="both")
home()
root.mainloop()