Steganography-Based Data Hiding System
This document provides a step-by-step guide to implementing a Steganography-based data hiding
system using Python. We will cover both the hiding and extraction of data in images using the LSB
method.
1. Project Overview
Steganography is the technique of hiding secret information within a file (e.g., image, audio) so that
it remains undetectable. This project focuses on hiding text within an image using the Least
Significant Bit (LSB) method.
2. Steps to Implement
The implementation consists of two main parts:
1. Hiding the secret message inside an image.
2. Extracting the hidden message from the stego image.
3. Hiding Data in an Image
The following Python code hides a secret message inside an image by modifying the least
significant bits of the pixel values.
from PIL import Image
def hide_data(image_path, secret_message, output_path):
image = Image.open(image_path)
binary_message = ''.join(format(ord(char), '08b') for char in secret_message) +
'00000000'
pixel_list = list(image.getdata())
new_pixels = []
binary_index = 0
for pixel in pixel_list:
new_pixel = list(pixel)
for i in range(3):
if binary_index < len(binary_message):
new_pixel[i] = (new_pixel[i] & ~1) | int(binary_message[binary_index])
binary_index += 1
new_pixels.append(tuple(new_pixel))
image.putdata(new_pixels)
image.save(output_path)
print("Data hidden successfully in", output_path)
# Example Usage
hide_data("input_image.png", "Hello, this is secret!", "stego_image.png")
4. Extracting Hidden Data from an Image
The following Python code extracts the hidden message from the stego image.
from PIL import Image
def extract_data(image_path):
image = Image.open(image_path)
binary_data = ""
for pixel in image.getdata():
for color in pixel[:3]:
binary_data += str(color & 1)
message = ""
for i in range(0, len(binary_data), 8):
byte = binary_data[i:i+8]
if byte == "00000000":
break
message += chr(int(byte, 2))
return message
# Example Usage
secret_message = extract_data("stego_image.png")
print("Hidden Message:", secret_message)
5. Conclusion
This project successfully implements a basic steganography technique for hiding and extracting
secret messages from images using the Least Significant Bit (LSB) method.