Checkpoint, configuration can now be done through DB and the site. Server settings are still on the file system

This commit is contained in:
2024-11-05 19:03:04 -05:00
parent b46ec98115
commit 9abdd18f33
8 changed files with 770 additions and 289 deletions

View File

@ -1,8 +1,10 @@
from PIL import Image
import numpy as np
from PIL import Image
def string_to_binary(message):
return ''.join(format(ord(char), '08b') for char in message)
return "".join(format(ord(char), "08b") for char in message)
def embed_message(image_path, message, exifraw):
# Open the image
@ -15,7 +17,7 @@ def embed_message(image_path, message, exifraw):
# Convert message to binary
binary_message = string_to_binary(message)
# Check if the message can fit in the image
if len(binary_message) > len(flat_array):
raise ValueError("Message is too long to be embedded in this image")
@ -28,11 +30,12 @@ def embed_message(image_path, message, exifraw):
stego_array = flat_array.reshape(img_array.shape)
# Create a new image from the modified array
stego_img = Image.fromarray(stego_array.astype('uint8'), img.mode)
stego_img = Image.fromarray(stego_array.astype("uint8"), img.mode)
# Save the image
stego_img.save(image_path, exif=exifraw)
def extract_message(image_path, message_length):
# Open the image
img = Image.open(image_path)
@ -43,9 +46,16 @@ def extract_message(image_path, message_length):
flat_array = img_array.flatten()
# Extract the binary message
binary_message = ''.join([str(pixel & 1) for pixel in flat_array[:message_length * 8]])
binary_message = "".join(
[str(pixel & 1) for pixel in flat_array[: message_length * 8]]
)
# Convert binary to string
message = ''.join([chr(int(binary_message[i:i+8], 2)) for i in range(0, len(binary_message), 8)])
message = "".join(
[
chr(int(binary_message[i : i + 8], 2))
for i in range(0, len(binary_message), 8)
]
)
return message