This Python script provides a simple way to encode text messages into image files and decode them back. It uses the OpenCV library to work with images and allows users to hide text within an image's pixel data.
Run the script and choose the mode: encode or decode. If encoding, provide the path to the image file and the text message you want to hide. If decoding, provide the path to the encoded image. The script will perform the selected operation and display the result.
The programme encodes text messages with XOR and stores them in images using Least Significant Bit (LSB) steganography. XOR encryption was picked because it is simple and removable, which is appropriate for the helpful and lightweight nature of this tool. LSB steganography is used because it can conceal information inside the image's noise level, rendering changes unnoticeable to the human eye and keeping the image's original look while securely encoding the data.
Loads the image and checks that it is a valid PNG file.
Encrypts or decrypts the given text using the XOR method. It's a static class that may be readily customised for various encryption methods.
The encrypted text is encoded into the picture using LSB steganography. It examines the text length to ensure that it is within the image's capacity.
Extracts and decrypts text from images by reversing the encoding process.
Controls the loading, encoding, and saving of the picture with embedded text.
The unittest framework is used to guarantee that the Image Text Encoder/Decoder tool is both robust and reliable. Below is an overview of the test cases used to validate each component of the system:
Valid Image File Confirms that the ImageLoader correctly identifies valid PNG files. A temporary image is created and verified to be recognized as a valid image file.
Ensures that an image is correctly loaded from the filesystem, checking both the presence of the loaded image and its dimensions to match the expected values.
Encode Text Verifies that text can be successfully encoded into an image. This test uses a blank image to encode a simple message, ensuring that the encoding process results in a modified image.
Save Encoded Image Tests the ability of the ImageEncoder to save an encoded image to the filesystem. It confirms that the saved file is correctly named to indicate its encoded status and then cleans up by removing the file.
XOR Encrypt/Decrypt Validates the Encryptor's ability to encrypt a message with a key and then decrypt it back to its original form. It checks that the decrypted message matches the original and that the encrypted form is different.
Decode Text Assesses the TextDecoder's capability to accurately extract and decrypt text from an encoded image. The test ensures that the decoded text matches the original message encoded in the image.
Invalid Image File Tests the system's response to an attempt at loading a non-existent image file, expecting a ValueError to be raised.
Verifies that encoding text which exceeds the capacity of the image results in a ValueError, preventing the operation.
This tool displays basic steganography and encryption techniques. It is intended for educational uses and is not suitable for secure communications until modified to use higher-level encryption methods.
- Python 3.x
- OpenCV (cv2) library
The script currently supports PNG image files only due to their lossless nature, which is crucial for accurately encoding and decoding text within an image.