Skip to content

chathaj/Encoding-Decoding-Messages-in-Images

main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
November 15, 2024 18:59

Image Text Encoder/Decoder

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.

How To Use:

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.

Algorithm Justification:

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.

How The Tool Works:

ImageLoader:

Loads the image and checks that it is a valid PNG file.

Encryptor:

Encrypts or decrypts the given text using the XOR method. It's a static class that may be readily customised for various encryption methods.

TextEncoder:

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.

TextDecoder:

Extracts and decrypts text from images by reversing the encoding process.

ImageEncoder:

Controls the loading, encoding, and saving of the picture with embedded text.

Test Cases:

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:

TestImageLoader:

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.

Load Image:

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.

TestTextEncoder:

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.

TestImageEncoder:

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.

TestEncryptor:

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.

TestTextDecoder:

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.

TestErrorHandling:

Invalid Image File Tests the system's response to an attempt at loading a non-existent image file, expecting a ValueError to be raised.

Text Too Long:

Verifies that encoding text which exceeds the capacity of the image results in a ValueError, preventing the operation.

Notes

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.

Requirements:

  1. Python 3.x
  2. OpenCV (cv2) library

Supported Files

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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Languages