-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimasteg.py
65 lines (51 loc) · 1.99 KB
/
imasteg.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
import tkinter as tk
from tkinter import filedialog, messagebox
from PIL import Image
import os
def embed_payload():
payload = payload_entry.get()
if not payload:
messagebox.showerror("Error", "Please enter a payload")
return
# Allow selection of multiple image types
file_path = filedialog.askopenfilename(filetypes=[
("Image Files", "*.png;*.jpg;*.jpeg;*.bmp;*.gif;*.tiff"),
("All Files", "*.*")
])
if not file_path:
messagebox.showerror("Error", "Please select an image")
return
try:
image = Image.open(file_path)
if image.mode != "RGB":
image = image.convert("RGB")
pixels = image.load()
# Convert payload to binary
binary_payload = ''.join(format(ord(char), '08b') for char in payload) + '00000000'
binary_index = 0
# Embed payload in image
for y in range(image.height):
for x in range(image.width):
if binary_index < len(binary_payload):
r, g, b = pixels[x, y]
# Modify the least significant bit of the red channel
r = (r & ~1) | int(binary_payload[binary_index])
binary_index += 1
pixels[x, y] = (r, g, b)
# Automatically save in the current directory
script_dir = os.getcwd() # Get the current working directory
file_name = "modified_image.png"
save_path = os.path.join(script_dir, file_name)
image.save(save_path)
messagebox.showinfo("Success", f"Payload embedded and image saved at: {save_path}")
except Exception as e:
messagebox.showerror("Error", f"An error occurred: {str(e)}")
# GUI setup
root = tk.Tk()
root.title("IMASTEG")
tk.Label(root, text="Enter Payload: ").pack(pady=5)
payload_entry = tk.Entry(root, width=50)
payload_entry.pack(pady=5)
embed_button = tk.Button(root, text="Embed Payload", command=embed_payload)
embed_button.pack(pady=20)
root.mainloop()