LSB Steganography with Python (hiddentxt.py)
This Python script provides tools for hiding and revealing secret messages within JPEG images using the Least Significant Bit (LSB) steganography technique.
Features:
- Encode a message into a JPEG image.
- Decode a hidden message from a JPEG image.
- Supports basic error handling for common issues like file access.
Usage:
The script operates in two modes: encode and decode. Use the appropriate command followed by the required arguments:
Encoding:
./hiddentxt.py encode input_image.jpg "secret message" output_image.jpg
Replace the placeholders with your actual file paths and message:
input_image.jpg: Path to the original JPEG image to embed the message in."secret message": The message you want to hide (enclosed in quotes).output_image.jpg: Path to save the modified JPEG image containing the hidden message.
Decoding:
./hiddentxt.py decode encoded_image.jpg
Replace the placeholder with the path to the encoded image (containing the hidden message).
Installation:
-
Ensure you have Python 3 installed on your system.
-
Install the required library using pip:
pip install Pillow
Disclaimer:
This script provides a basic implementation of LSB steganography. It may be vulnerable to steganalysis techniques that can detect the presence of hidden messages. Consider alternative steganography methods or encryption for more secure message hiding.
Explanation:
LSB steganography manipulates the least significant bit of each color channel (red, green, blue) in the image data. This allows embedding a message with minimal visual impact on the original image.
The script performs the following steps during encoding:
- Converts the message to a binary string.
- Iterates through the image pixels and modifies the least significant bit of each color channel to embed the message bits.
- Saves the modified image with the hidden message.
Decoding reverses the process:
- Extracts the hidden message bits from the least significant bits of the image data.
- Converts the binary message to a readable string.
- Displays the decoded message.
Additional Notes:
- The script checks for image file existence and basic error handling during image processing.
- The message length is limited by the image size. Ensure the message can fit within the image's available bits for successful encoding.
- Changing the output file extension (e.g., from
.jpgto.png) will convert the format.
Future Improvements:
- Implement support for different image formats (beyond JPEG).
- Add functionalities like password protection for message decryption.
We hope this script provides a useful tool for basic LSB steganography experiments. Remember to use it responsibly and ethically.