mirror of
https://github.com/cedricbonhomme/Stegano.git
synced 2025-06-28 03:06:14 +02:00
Misc improvements.
This commit is contained in:
parent
6cd22dfe72
commit
d850bbd8a0
6 changed files with 30 additions and 31 deletions
|
@ -40,11 +40,14 @@ def hide(input_image_file, message, auto_convert_rgb=False):
|
|||
Hide a message (string) in an image with the
|
||||
LSB (Least Significant Bit) technique.
|
||||
"""
|
||||
img = Image.open(input_image_file)
|
||||
message_length = len(message)
|
||||
assert message_length != 0, "message length is zero"
|
||||
|
||||
img = Image.open(input_image_file)
|
||||
if img.mode != 'RGB':
|
||||
if not auto_convert_rgb:
|
||||
print('The mode of the image is not RGB. Mode is {}'.format(img.mode))
|
||||
print('The mode of the image is not RGB. Mode is {}'.\
|
||||
format(img.mode))
|
||||
answer = input('Convert the image to RGB ? [Y / n]\n') or 'Y'
|
||||
if answer.lower() == 'n':
|
||||
raise Exception('Not a RGB image.')
|
||||
|
@ -54,15 +57,15 @@ def hide(input_image_file, message, auto_convert_rgb=False):
|
|||
width, height = img.size
|
||||
index = 0
|
||||
|
||||
message = str(len(message)) + ":" + str(message)
|
||||
message = str(message_length) + ":" + str(message)
|
||||
message_bits = "".join(tools.a2bits_list(message))
|
||||
message_bits += '0' * ((3 - (len(message_bits) % 3)) % 3)
|
||||
|
||||
npixels = width * height
|
||||
len_message_bits = len(message_bits)
|
||||
if len_message_bits > npixels * 3:
|
||||
raise Exception("""The message you want to hide is too long (%s > %s).""" % (len(message_bits), npixels * 3))
|
||||
|
||||
raise Exception("The message you want to hide is too long: {}).". \
|
||||
format(message_length))
|
||||
for row in range(height):
|
||||
for col in range(width):
|
||||
if index + 3 <= len_message_bits :
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue