From 0ae1852d870d34ba8423b8de62f9aff1be963cd8 Mon Sep 17 00:00:00 2001 From: Shyam <140179838+MadMax1311@users.noreply.github.com> Date: Mon, 16 Oct 2023 14:01:10 +0530 Subject: [PATCH 1/2] StenographyEncoding.py --- StenographyEncoding.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 StenographyEncoding.py diff --git a/StenographyEncoding.py b/StenographyEncoding.py new file mode 100644 index 0000000000..c294890988 --- /dev/null +++ b/StenographyEncoding.py @@ -0,0 +1,33 @@ +# Function to encode a message into an image +def encode_image(input_image_path, output_image_path, message): + img = Image.open(input_image_path) + width, height = img.size + pixel_index = 0 + binary_message = ''.join(format(ord(char), '08b') for char in message) + + if len(binary_message) > width * height: + print("Message is too large for this image.") + return + + for x in range(width): + for y in range(height): + pixel = list(img.getpixel((x, y))) + for color_channel in range(3): # RGB channels + if pixel_index < len(binary_message): + pixel[color_channel] = int(bin(pixel[color_channel])[2:-1] + binary_message[pixel_index], 2) + pixel_index += 1 + else: + break + img.putpixel((x, y), tuple(pixel)) + + img.save(output_image_path) + + +# Example usage +message_to_hide = "This example of Stenography." +input_image = "madmax.jpg" +output_image = "output_image.png" + +# Encode the message into the image +encode_image(input_image, output_image, message_to_hide) +print("Encoded Message: ",message_to_hide) From dd388808593c5d284f5c3c4d5e31abc367b14e93 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 16 Oct 2023 08:32:54 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- StenographyEncoding.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/StenographyEncoding.py b/StenographyEncoding.py index c294890988..ec6325f026 100644 --- a/StenographyEncoding.py +++ b/StenographyEncoding.py @@ -3,7 +3,7 @@ def encode_image(input_image_path, output_image_path, message): img = Image.open(input_image_path) width, height = img.size pixel_index = 0 - binary_message = ''.join(format(ord(char), '08b') for char in message) + binary_message = "".join(format(ord(char), "08b") for char in message) if len(binary_message) > width * height: print("Message is too large for this image.") @@ -14,7 +14,9 @@ def encode_image(input_image_path, output_image_path, message): pixel = list(img.getpixel((x, y))) for color_channel in range(3): # RGB channels if pixel_index < len(binary_message): - pixel[color_channel] = int(bin(pixel[color_channel])[2:-1] + binary_message[pixel_index], 2) + pixel[color_channel] = int( + bin(pixel[color_channel])[2:-1] + binary_message[pixel_index], 2 + ) pixel_index += 1 else: break @@ -30,4 +32,4 @@ def encode_image(input_image_path, output_image_path, message): # Encode the message into the image encode_image(input_image, output_image, message_to_hide) -print("Encoded Message: ",message_to_hide) +print("Encoded Message: ", message_to_hide)