Steganography is the practice of concealing a secret message within another message or file. In image steganography, a secret message is hidden within an image without changing the visual appearance of the image. In this answer, I’ll show you how to implement image steganography using Python.
First, we need to install the Pillow library, which is a fork of the Python Imaging Library (PIL) and provides support for opening, manipulating, and saving many different image file formats.
You can install the Pillow library using pip by running the following command in your command prompt or terminal:
pip install pillow
Once Pillow is installed, we can start implementing image steganography. Here’s a simple example of how to hide a message within an image:
from PIL import Image # Open the image img = Image.open('image.png') # Convert the image to RGB mode img = img.convert('RGB') # Get the size of the image width, height = img.size # Get the pixels of the image pixels = img.load() # Define the message to hide message = 'This is a secret message.' # Convert the message to binary binary_message = ''.join(format(ord(char), '08b') for char in message) # Add a delimiter to the binary message delimiter = '00000000' binary_message += delimiter # Get the length of the binary message message_length = len(binary_message) # Make sure the message can fit in the image if message_length > (width * height): raise ValueError('Message is too long to fit in the image.') # Loop through each pixel of the image and hide the message in the LSB of each color channel index = 0 for y in range(height): for x in range(width): r, g, b = pixels[x, y] if index < message_length: r = (r & 254) | int(binary_message[index]) index += 1 if index < message_length: g = (g & 254) | int(binary_message[index]) index += 1 if index < message_length: b = (b & 254) | int(binary_message[index]) index += 1 pixels[x, y] = (r, g, b) # Save the image with the hidden message img.save('image_with_message.png')
In this example, we open an image called “image.png” and convert it to RGB mode. We then get the size of the image and the pixels of the image using the load()
method. We define a message to hide in the image and convert it to binary. We add a delimiter to the binary message to mark the end of the message. We get the length of the binary message and make sure it can fit in the image.
We then loop through each pixel of the image and hide the message in the least significant bit (LSB) of each color channel (red, green, and blue) if there is still message left to hide. Finally, we save the image with the hidden message as “image_with_message.png”.
To extract the hidden message from the image, we can use the following code:
from PIL import Image # Open the image with the hidden message img = Image.open('image_with_message.png') # Convert the image to RGB mode img = img.convert('RGB') # Get the size of the image width, height = img.size # Get the pixels of the image pixels = img.load() # Extract the hidden message from the LSB of each color channel binary_message = '' for y in range(height): for x in range(width): r,
Understanding the benefits of using Steganography over Cryptography:
Steganography and cryptography are both techniques used for hiding information, but they differ in their approach and goals.
Cryptography involves scrambling or encrypting data so that it becomes unintelligible to unauthorized users. The primary goal of cryptography is to ensure confidentiality, integrity, and authenticity of the data. In cryptography, the encrypted data is still visible, but it is indecipherable without the correct decryption key.
On the other hand, Steganography involves hiding information within other data or media, such as text, images, or audio files. The primary goal of Steganography is to ensure that the existence of the hidden data remains secret. The hidden data is invisible, and the media appears unchanged to an observer.
Here are some benefits of using Steganography over Cryptography:
- Security: Steganography provides additional security because the very existence of the hidden data remains unknown to an observer. Even if someone intercepts the data, they may not realize that there is hidden information present. In contrast, Cryptography alone only obscures the meaning of the data, but the encrypted data is still visible, which could make it a target for attacks.
- Unobtrusive: Steganography is more unobtrusive than Cryptography because it does not affect the appearance or structure of the media that the data is hidden within. This means that the hidden data is less likely to arouse suspicion than if the data was encrypted, which can be detected through its scrambled appearance.
- Deniability: Steganography provides plausible deniability because an observer may assume that any hidden data is merely a part of the original media, rather than a separate message. In contrast, Cryptography only obscures the meaning of the data but does not provide plausible deniability.
- Redundancy: Steganography can provide redundancy because the hidden data can be spread across multiple media, providing multiple opportunities for recovery. In contrast, Cryptography is vulnerable to data loss because the encrypted data must be decrypted to recover the original data.
In summary, Steganography and Cryptography are both valuable tools for securing data, but they differ in their approach and goals. Steganography provides additional security and unobtrusiveness, plausible deniability, and redundancy, making it a powerful technique for securing sensitive data. However, Steganography should not be used as a replacement for Cryptography but rather as a complementary technique to provide additional layers of security.
Understanding the types of Steganography:
Steganography can be classified into different types based on the type of cover media or the technique used for hiding the information. Here are some of the most common types of steganography:
- Image Steganography: In this type of steganography, the hidden message is embedded within an image. The image can be in any format, such as BMP, PNG, JPEG, or GIF. The hidden message can be concealed by modifying the pixels of the image or by modifying the metadata associated with the image.
- Audio Steganography: In this type of steganography, the hidden message is embedded within an audio file. The audio file can be in any format, such as MP3, WAV, or AIFF. The hidden message can be concealed by modifying the amplitude or frequency of the audio signal.
- Video Steganography: In this type of steganography, the hidden message is embedded within a video file. The video file can be in any format, such as MP4, AVI, or MOV. The hidden message can be concealed by modifying the pixels of the video frames or by modifying the metadata associated with the video.
- Text Steganography: In this type of steganography, the hidden message is embedded within a text document. The hidden message can be concealed by using invisible characters, changing the font or font size, or by using a specific language or dialect that contains hidden meaning.
- Network Steganography: In this type of steganography, the hidden message is embedded within network traffic. The hidden message can be concealed by modifying the timing or sequence of network packets or by using specific network protocols that allow for hidden messages.
- Printer Steganography: In this type of steganography, the hidden message is embedded within the printed output. The hidden message can be concealed by using invisible ink or by modifying the arrangement of the printed characters.
These are some of the common types of steganography, but there are also other variations and techniques that can be used for hiding information. It’s important to note that steganography should only be used for legitimate purposes and not for illegal activities such as espionage or terrorism.
Basic Model of Steganography:
The basic model of Steganography involves three main components:
- Cover Media: This is the original media or data that is used as a carrier for the hidden message. The cover media can be an image, audio file, video file, text document, or any other type of digital media.
- Secret Message: This is the information that needs to be hidden within the cover media. The secret message can be a text message, an image, an audio clip, a video clip, or any other type of data that needs to be concealed.
- Steganography Algorithm: This is the technique or algorithm used to embed the secret message within the cover media. The steganography algorithm works by modifying the cover media in such a way that the changes are imperceptible to human senses but can be detected using specialized software.
The basic model of steganography involves the following steps:
- Selection of Cover Media: The first step is to select the appropriate cover media for hiding the secret message. The cover media should be chosen in such a way that it appears natural and does not arouse suspicion.
- Encoding the Secret Message: The next step is to encode the secret message in a format that can be embedded within the cover media. The secret message is typically compressed and encrypted to ensure that it remains hidden.
- Embedding the Secret Message: The secret message is then embedded within the cover media using the steganography algorithm. The algorithm modifies the cover media in such a way that the changes are imperceptible to human senses but can be detected using specialized software.
- Extraction of the Secret Message: To extract the hidden message, the steganography algorithm is used to detect the modifications made to the cover media. The algorithm then extracts the hidden message from the cover media and decodes it to reveal the original message.
In summary, the basic model of steganography involves hiding a secret message within a cover media using a steganography algorithm. The success of steganography depends on the ability to embed the secret message in such a way that it remains undetected.
Understanding the Least Significant Bit Steganography:
Least Significant Bit (LSB) Steganography is a type of steganography technique that is commonly used to hide information within digital images. The technique works by embedding the secret message into the least significant bit (LSB) of each pixel in the cover image. The least significant bit represents the smallest binary value in a pixel’s color code, and is often ignored by the human eye.
In LSB Steganography, the process of embedding the secret message involves replacing the LSB of each pixel with a bit of the secret message. For example, if the binary code of the pixel is 01100110, and the binary code of the secret message bit is 1, the LSB of the pixel is replaced with the secret message bit, resulting in a new binary code of 01100111. This process is repeated for each pixel in the image until the entire secret message is embedded.
To extract the secret message from the stego image, the reverse process is used. The LSB of each pixel in the stego image is extracted and combined to form the binary code of the secret message.
One of the advantages of LSB Steganography is that it does not significantly alter the cover image, making it difficult to detect with the naked eye. However, the technique has limitations, such as the amount of information that can be embedded within an image without significantly affecting its quality, and the possibility of losing the hidden message if the image is compressed or edited.
LSB Steganography can be implemented using various programming languages, including Python, Java, and C++. However, it is important to use the technique for legitimate purposes and not for any illegal activities.
Understanding the working of the Least Significant Bit technique:
The working of Least Significant Bit (LSB) Steganography involves the following steps:
- Selection of Cover Image: The first step is to select a cover image to embed the secret message. The cover image should be chosen in such a way that it appears natural and does not arouse suspicion.
- Encoding the Secret Message: The next step is to encode the secret message in a format that can be embedded within the cover image. The secret message is typically compressed and encrypted to ensure that it remains hidden.
- Embedding the Secret Message: The secret message is then embedded within the cover image using the LSB technique. The LSB of each pixel in the cover image is replaced with a bit of the secret message. This process is typically done for the least significant bit of the color channels (red, green, and blue) of each pixel.
- Receiving the Stego Image: The stego image is then generated, which contains the cover image with the embedded secret message.
- Extraction of the Secret Message: To extract the hidden message, the LSB of each pixel in the stego image is extracted and combined to form the binary code of the secret message. The binary code is then decrypted and decompressed to reveal the original message.
One of the advantages of LSB Steganography is that it can be implemented using simple programming techniques and does not require any complex algorithms. However, it has limitations, such as the amount of information that can be embedded within an image without significantly affecting its quality, and the possibility of losing the hidden message if the image is compressed or edited.
To improve the security and robustness of LSB Steganography, various techniques such as error correction codes and spread spectrum techniques can be used. These techniques can help to ensure that the hidden message remains intact even in the presence of noise or distortions in the cover image.
Hiding Text within an Image using Python:
To hide text within an image using Python, we can use the following steps:
- Import the necessary libraries: We need to import the Pillow library in Python, which is a fork of the Python Imaging Library (PIL), and is used for image processing.
from PIL import Image
- Open the cover image: We need to open the cover image, which is the image in which we want to hide the text.
img = Image.open('cover_image.png')
- Convert the image to RGB: We need to convert the image to RGB format, which is the standard format for most digital images.
img = img.convert('RGB')
- Get the pixel data: We need to get the pixel data from the image, which is an array of color values for each pixel in the image.
pixel_data = img.load()
- Encode the secret message: We need to encode the secret message in a format that can be embedded within the image. We can use the UTF-8 encoding to convert the text to a byte string.
secret_message = "This is a secret message" byte_message = secret_message.encode('utf-8')
- Embed the secret message: We can use the LSB technique to embed the secret message within the image. We need to iterate over each pixel in the image and replace the least significant bit of each color channel with a bit from the secret message.
index = 0 for i in range(img.size[0]): for j in range(img.size[1]): r, g, b = pixel_data[i, j] if index < len(byte_message): r_bit = byte_message[index] & 1 pixel_data[i, j] = (r & 254) | r_bit index += 1
- Save the stego image: We need to save the modified image as a new image, which is the stego image.
img.save('stego_image.png')
- Extract the hidden message: To extract the hidden message from the stego image, we can use the same LSB technique. We need to iterate over each pixel in the image and extract the least significant bit of each color channel to form the byte string.
stego_img = Image.open('stego_image.png') stego_pixel_data = stego_img.load() extracted_message = b"" for i in range(stego_img.size[0]): for j in range(stego_img.size[1]): r, g, b = stego_pixel_data[i, j] extracted_message += bytes([r & 1]) extracted_text = extracted_message.decode('utf-8') print(extracted_text)
This is a basic example of how to hide text within an image using Python and the LSB technique. However, it is important to note that this technique has limitations, such as the amount of information that can be embedded within an image without significantly affecting its quality, and the possibility of losing the hidden message if the image is compressed or edited.
Importing the Python libraries:
Sure! Here are some of the commonly used Python libraries for steganography:
- Pillow: A fork of the Python Imaging Library (PIL) that is used for opening, manipulating, and saving many different image file formats.
from PIL import Image
- Numpy: A library used for mathematical operations and multi-dimensional arrays.
import numpy as np
- OpenCV: A library used for computer vision applications such as image processing and object detection.
import cv2
- Stegano: A library that provides various steganography techniques such as LSB, DCT, and spread spectrum.
import stegano
- F5-Steganography: A library that provides F5 steganography, which is a technique that embeds data in the frequency domain of an image.
import f5
- Hid: A library that provides various steganography techniques such as LSB and F5.
import hid
These are just a few of the many libraries available for steganography in Python. The choice of library will depend on the specific requirements of the project.
Converting Types to Binary:
To convert types to binary in Python, we can use the built-in bin()
function. The bin()
function takes an integer or any other data type and returns its binary representation in the form of a string.
Here are some examples:
- Convert an integer to binary:
num = 42 binary_num = bin(num) print(binary_num)
Output:
0b101010
- Convert a string to binary:
string = "Hello, world!" binary_string = ''.join(format(ord(c), '08b') for c in string) print(binary_string)
Output:
010010000110010101101100011011000110111100100000011101110110111101110010011011000110010000100001
- Convert a float to binary:
num = 3.14 binary_num = bin(int(num * (2 ** 32))) print(binary_num)
Output:
0b11000010100101111000110101001110
Note that the bin()
function returns a string starting with the prefix ‘0b’, which represents that the number is in binary form. If we want to remove the prefix, we can use string slicing to extract the binary digits. For example, to extract the binary digits from the above outputs, we can use binary_num[2:]
.
Hiding Secret Data in the Image:
To hide secret data in an image using steganography, we can use the Least Significant Bit (LSB) technique. The LSB technique involves replacing the least significant bits of the pixels in an image with the bits of the secret data. The change in the least significant bits of the pixels is usually imperceptible to the human eye, and thus the image looks unchanged to the casual observer.
Here is an example of how to hide secret data in an image using the LSB technique in Python using the Pillow library:
from PIL import Image def encode_message(image_path, message): # Open the image and convert it to RGB format image = Image.open(image_path).convert('RGB') # Convert the message to binary format binary_message = ''.join(format(ord(char), '08b') for char in message) # Get the width and height of the image width, height = image.size # Keep track of the number of bits encoded in the image bits_encoded = 0 # Loop through each pixel of the image for x in range(width): for y in range(height): # Get the RGB values of the current pixel r, g, b = image.getpixel((x, y)) # Replace the least significant bit of each color component with the secret bit if bits_encoded < len(binary_message): r = r & ~1 | int(binary_message[bits_encoded]) bits_encoded += 1 if bits_encoded < len(binary_message): g = g & ~1 | int(binary_message[bits_encoded]) bits_encoded += 1 if bits_encoded < len(binary_message): b = b & ~1 | int(binary_message[bits_encoded]) bits_encoded += 1 # Set the modified pixel back in the image image.putpixel((x, y), (r, g, b)) # If all the secret data has been encoded, exit the loop if bits_encoded >= len(binary_message): break else: continue break # Save the modified image to a new file image.save('encoded_image.png') # Example usage encode_message('original_image.png', 'This is a secret message.')
In this example, the encode_message()
function takes the path of the original image and the secret message as inputs. It then opens the image and converts it to RGB format, and converts the message to binary format. It then loops through each pixel of the image and replaces the least significant bit of each color component (red, green, and blue) with the corresponding bit of the secret message. It keeps track of the number of bits encoded in the image, and exits the loop when all the secret data has been encoded. Finally, it saves the modified image to a new file named ‘encoded_image.png’.
Note that the above implementation only supports encoding of messages that can fit within the least significant bits of each pixel. For larger messages, more advanced steganography techniques may be required.
Decoding the hidden message from the Steganographic image:
To decode a hidden message from a steganographic image using the LSB technique in Python, we can extract the least significant bits of the pixels in the image and convert them back to ASCII characters. Here is an example implementation using the Pillow library:
from PIL import Image def decode_message(image_path): # Open the image and convert it to RGB format image = Image.open(image_path).convert('RGB') # Get the width and height of the image width, height = image.size # Keep track of the number of bits decoded from the image bits_decoded = 0 # Initialize an empty message string message = '' # Loop through each pixel of the image for x in range(width): for y in range(height): # Get the RGB values of the current pixel r, g, b = image.getpixel((x, y)) # Extract the least significant bit of each color component and append it to the message message += bin(r)[-1] bits_decoded += 1 if bits_decoded < len(bin(g)): message += bin(g)[-1] bits_decoded += 1 if bits_decoded < len(bin(b)): message += bin(b)[-1] bits_decoded += 1 # If the message is complete, convert it to ASCII and return it if bits_decoded >= 8 and message[-8:] == '00000000': return ''.join(chr(int(message[i:i+8], 2)) for i in range(0, len(message)-8, 8)) # If the message is not complete, return None return None # Example usage hidden_message = decode_message('encoded_image.png') print(hidden_message)
In this example, the decode_message()
function takes the path of the steganographic image as an input. It then opens the image and converts it to RGB format. It then loops through each pixel of the image and extracts the least significant bit of each color component (red, green, and blue) and appends it to the message string. It keeps track of the number of bits decoded from the image and exits the loop when it encounters the null terminator character (8 consecutive zeros). Finally, it converts the binary message to ASCII characters and returns it.
Note that the above implementation assumes that the message is null-terminated, meaning that it ends with 8 consecutive zeros. If the message is not null-terminated, a different mechanism for indicating the end of the message would need to be used.
Encoding the message:
To encode a message using the LSB technique in Python, we can replace the least significant bits of the pixels in an image with the binary representation of the message. Here is an example implementation using the Pillow library:
from PIL import Image def encode_message(image_path, message): # Open the image and convert it to RGB format image = Image.open(image_path).convert('RGB') # Convert the message to binary and append the null terminator character binary_message = ''.join(format(ord(c), '08b') for c in message) + '00000000' # Get the width and height of the image width, height = image.size # Keep track of the number of bits encoded in the image bits_encoded = 0 # Loop through each pixel of the image for x in range(width): for y in range(height): # Get the RGB values of the current pixel r, g, b = image.getpixel((x, y)) # Replace the least significant bit of each color component with the next bit of the message if bits_encoded < len(binary_message): r = (r & ~1) | int(binary_message[bits_encoded]) bits_encoded += 1 if bits_encoded < len(binary_message): g = (g & ~1) | int(binary_message[bits_encoded]) bits_encoded += 1 if bits_encoded < len(binary_message): b = (b & ~1) | int(binary_message[bits_encoded]) bits_encoded += 1 # If all bits of the message have been encoded, save and return the modified image if bits_encoded >= len(binary_message): image.putpixel((x, y), (r, g, b)) image.save('encoded_image.png') return image # If the message could not be encoded in the image, return None return None # Example usage image_with_hidden_message = encode_message('original_image.png', 'This is a secret message!')
In this example, the encode_message()
function takes the path of the original image and the message to be encoded as inputs. It then opens the image and converts it to RGB format. It converts the message to binary and appends the null terminator character. It then loops through each pixel of the image and replaces the least significant bit of each color component (red, green, and blue) with the next bit of the message. It keeps track of the number of bits encoded in the image and exits the loop when all bits of the message have been encoded. Finally, it saves the modified image and returns it.
Note that the above implementation assumes that the message is null-terminated, meaning that it ends with 8 consecutive zeros. If the message is not null-terminated, a different mechanism for indicating the end of the message would need to be used. Additionally, encoding a large message in an image can cause significant distortion and loss of image quality, so it is important to choose an appropriate message size and image resolution to balance message secrecy and image fidelity.
Decoding the message:
To decode the hidden message from an LSB-encoded image in Python, we can extract the least significant bits of the color components of each pixel and concatenate them to form the binary representation of the message. Here is an example implementation:
from PIL import Image def decode_message(image_path): # Open the image and convert it to RGB format image = Image.open(image_path).convert('RGB') # Get the width and height of the image width, height = image.size # Keep track of the number of bits decoded from the image bits_decoded = 0 # Initialize the decoded message as an empty string decoded_message = '' # Loop through each pixel of the image for x in range(width): for y in range(height): # Get the RGB values of the current pixel r, g, b = image.getpixel((x, y)) # Extract the least significant bit of each color component and append it to the decoded message decoded_message += str(r & 1) bits_decoded += 1 if bits_decoded < len(decoded_message): decoded_message += str(g & 1) bits_decoded += 1 if bits_decoded < len(decoded_message): decoded_message += str(b & 1) bits_decoded += 1 # If the null terminator character has been reached, return the decoded message if decoded_message[-8:] == '00000000': return ''.join(chr(int(decoded_message[i:i+8], 2)) for i in range(0, len(decoded_message)-8, 8)) # If the null terminator character was not found, return None return None # Example usage hidden_message = decode_message('encoded_image.png') print(hidden_message)
In this example, the decode_message()
function takes the path of the encoded image as input. It then opens the image and converts it to RGB format. It loops through each pixel of the image and extracts the least significant bit of each color component (red, green, and blue). It concatenates these bits to form the binary representation of the hidden message. It keeps track of the number of bits decoded and exits the loop when it encounters the null terminator character. Finally, it converts the binary message to ASCII characters and returns the decoded message.
Note that the above implementation assumes that the message is null-terminated, meaning that it ends with 8 consecutive zeros. If the message is not null-terminated, a different mechanism for indicating the end of the message would need to be used. Additionally, decoding a message from an LSB-encoded image requires the original message to have been encoded using the same algorithm and parameters (e.g., image resolution, message size), so it is important to keep this in mind when using this technique for secret communication.
The main function:
Sure, here is an example main function that uses the encode_message()
and decode_message()
functions to hide and extract a message from an image:
from PIL import Image def encode_message(image_path, message): # Encode the message into the image using LSB steganography # ... # Return the encoded image def decode_message(image_path): # Decode the message from the image using LSB steganography # ... # Return the decoded message def main(): # Define the path of the image and the message to encode image_path = 'image.png' message = 'This is a secret message!' # Encode the message into the image using LSB steganography encoded_image = encode_message(image_path, message) # Save the encoded image to a file encoded_image.save('encoded_image.png') # Decode the message from the encoded image decoded_message = decode_message('encoded_image.png') # Print the decoded message print(decoded_message) if __name__ == '__main__': main()
In this example, the main()
function defines the path of the image and the message to encode. It calls the encode_message()
function to hide the message in the image using LSB steganography, and saves the resulting image to a file called encoded_image.png
. It then calls the decode_message()
function to extract the message from the encoded image, and prints the resulting message to the console.
Note that in a real-world scenario, the image and message would likely be provided by external sources (e.g., a user uploading an image and entering a message in a web form), and the encoded image would be delivered to the recipient through some communication channel (e.g., email, social media).
The Complete Program:
Sure! Here’s the complete Python program that uses LSB steganography to hide and extract a message from an image:
from PIL import Image # Convert an integer to binary def int_to_bin(n): return format(n, '08b') # Convert a binary string to an integer def bin_to_int(b): return int(b, 2) # Convert a string to a binary string def str_to_bin(s): return ''.join([int_to_bin(ord(c)) for c in s]) # Convert a binary string to a string def bin_to_str(b): return ''.join([chr(bin_to_int(b[i:i+8])) for i in range(0, len(b), 8)]) # Hide a message in an image using LSB steganography def encode_message(image_path, message): # Open the image file image = Image.open(image_path) # Convert the message to binary message_bin = str_to_bin(message) # Get the dimensions of the image and calculate the maximum message size width, height = image.size max_message_size = width * height * 3 // 8 # Check if the message is too big to fit in the image if len(message_bin) > max_message_size: raise ValueError('Message too large to fit in image') # Encode the message length in the first 32 bits of the image length_bin = int_to_bin(len(message_bin)) pixels = list(image.getdata()) pixels[0] = tuple(int(p[:-1] + length_bin[i:i+1], 2) for i, p in enumerate(int_to_bin(pixels[0][0]))) image.putdata(pixels) # Encode the message in the image pixels = list(image.getdata()) message_bin += '0' * (max_message_size - len(message_bin)) for i in range(len(message_bin)): pixel = pixels[i] pixels[i] = tuple(int(p[:-1] + message_bin[i:i+1], 2) for p in int_to_bin(pixel)) image.putdata(pixels) # Return the encoded image return image # Extract a message from an image using LSB steganography def decode_message(image_path): # Open the image file image = Image.open(image_path) # Extract the message length from the first 32 bits of the image pixels = list(image.getdata()) length_bin = ''.join([int_to_bin(p)[-1] for p in int_to_bin(pixels[0][0])]) message_length = bin_to_int(length_bin) # Extract the message from the image pixels = pixels[1:message_length*8+1] message_bin = ''.join([int_to_bin(p)[-1] for pixel in pixels for p in int_to_bin(pixel)]) message = bin_to_str(message_bin) # Return the decoded message return message # Main function def main(): # Define the path of the image and the message to encode image_path = 'image.png' message = 'This is a secret message!' # Encode the message into the image using LSB steganography encoded_image = encode_message(image_path, message) # Save the encoded image to a file encoded_image.save('encoded_image.png') # Decode the message from the encoded image decoded_message = decode_message('encoded_image.png') # Print the decoded message print(decoded_message) if __name__ == '__main__': main()
This program includes the encode_message()
and decode_message()
functions.