This project allows you to hide text within an image using the Least Significant Bit (LSB) method. It also integrates AES encryption to secure the text before embedding it inside the image. Here's the process:
- Encryption: The text is encrypted using AES with a password.
- Conversion: The encrypted text is then converted into binary form.
- Embedding: The binary data is embedded in the least significant bits of the RGB channels of the image.
- Extraction: The encrypted text is extracted from the image using the LSB method and decrypted with the password.
cryptography
: AES encryption library. Install it using:pip install cryptography
Pillow
: Python Imaging Library (PIL) for working with images. Install it using:pip install pillow
- generate_key(password): Generates a key from the provided password.
- encrypt_text(text, password): Encrypts the given text using AES encryption.
- decrypt_text(encrypted_text, password): Decrypts the encrypted text using the AES key generated from the password.
- text_to_bin(text): Converts the input text into its binary representation.
- bin_to_text(binary_data): Converts a binary string back to readable text.
- hide_text_in_image(image_path, text, output_image_path, password): Hides the encrypted text within the image.
- extract_text_from_image(image_path, password): Extracts and decrypts the hidden text from the image.
- Encrypt the text: The input text is encrypted using the AES algorithm with a password.
- Convert to binary: The encrypted text is then converted into a binary form for LSB embedding.
- Embed the binary data in an image: The binary data is embedded into the image's least significant bits of the RGB color channels.
- Extract the binary data: The encrypted binary data is extracted using the same password.
- Decrypt the binary data: Finally, the encrypted text is decrypted back to its original form.
image_path = "photo.jpg"
text = "just some initial text to hide in the image."
output_image_path = "hidden_image.png"
password = "konopasswordlagena"
# Hide the text
hide_text_in_image(image_path, text, output_image_path, password)
# Extract the text
extracted_text = extract_text_from_image(output_image_path, password)
print("Extracted Text:", extracted_text)
- The
hide_text_in_image()
function embeds the encrypted text into the image and saves it asoutput_image_path
. - The
extract_text_from_image()
function retrieves and decrypts the hidden text from the image, provided the correct password.
This project is open-source under the MIT License. Feel free to modify and distribute it as needed.
GitHub: NibirMahmud
Date: 2025-03-24