-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSteganography.py
More file actions
61 lines (41 loc) · 1.51 KB
/
Steganography.py
File metadata and controls
61 lines (41 loc) · 1.51 KB
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
import os
def get_valid_file():
filename = input("Enter the PNG file name: ").strip()
return filename if os.path.exists(filename) else "r.png"
def hide_data_in_png():
png_filename = get_valid_file()
print(f"Using file: {png_filename}")
hidden_data = input("Enter the data to hide: ").encode()
with open(png_filename, "ab") as f:
f.write(hidden_data)
print(f"Data hidden successfully in '{png_filename}'.")
def extract_hidden_data():
png_filename = input("Enter the PNG file name: ").strip()
if not os.path.exists(png_filename):
print("Error: File not found!")
return
with open(png_filename, "rb") as f:
content = f.read()
iend_marker = b"\x49\x45\x4E\x44\xAE\x42\x60\x82"
offset = content.find(iend_marker)
if offset == -1:
print("Error: IEND marker not found! Not a valid PNG file.")
return
extra_data_start = offset + len(iend_marker)
extra_data = content[extra_data_start:]
if extra_data:
print("🔍 Hidden Data Found:", extra_data.decode(errors="ignore"))
with open("hidden_data.txt", "wb") as hidden_file:
hidden_file.write(extra_data)
print("Hidden data saved to 'hidden_data.txt'")
else:
print("No hidden data found.")
choice = input(
"Do you want to (1) Hide Data or (2) Extract Data? Enter 1 or 2: "
).strip()
if choice == "1":
hide_data_in_png()
elif choice == "2":
extract_hidden_data()
else:
print("Invalid choice. Please enter 1 or 2.")