mirror of
https://github.com/cedricbonhomme/Stegano.git
synced 2025-06-28 11:16:14 +02:00
Introduce a new argument in a2bits_list in order to specify the encoding of the string (unicode)
This commit is contained in:
parent
49964d4f16
commit
5f5c07493c
6 changed files with 77 additions and 28 deletions
|
@ -32,7 +32,11 @@ from PIL import Image
|
|||
from stegano import tools
|
||||
from . import generators
|
||||
|
||||
def hide(input_image_file, message, generator, auto_convert_rgb=False):
|
||||
def hide(input_image_file,
|
||||
message,
|
||||
generator,
|
||||
encoding='UTF-8',
|
||||
auto_convert_rgb=False):
|
||||
"""Hide a message (string) in an image with the
|
||||
LSB (Least Significant Bit) technique.
|
||||
"""
|
||||
|
@ -55,7 +59,7 @@ def hide(input_image_file, message, generator, auto_convert_rgb=False):
|
|||
index = 0
|
||||
|
||||
message = str(message_length) + ":" + str(message)
|
||||
message_bits = "".join(tools.a2bits_list(message))
|
||||
message_bits = "".join(tools.a2bits_list(message, encoding))
|
||||
message_bits += '0' * ((3 - (len(message_bits) % 3)) % 3)
|
||||
|
||||
npixels = width * height
|
||||
|
@ -90,7 +94,7 @@ def hide(input_image_file, message, generator, auto_convert_rgb=False):
|
|||
return encoded
|
||||
|
||||
|
||||
def reveal(input_image_file, generator):
|
||||
def reveal(input_image_file, generator, encoding='UTF-8'):
|
||||
"""Find a message in an image (with the LSB technique).
|
||||
"""
|
||||
img = Image.open(input_image_file)
|
||||
|
@ -104,9 +108,9 @@ def reveal(input_image_file, generator):
|
|||
generated_number = next(generator)
|
||||
# color = [r, g, b]
|
||||
for color in img_list[generated_number]:
|
||||
buff += (color&1)<<(31-count)
|
||||
buff += (color&1)<<(tools.ENCODINGS[encoding]-1 - count)
|
||||
count += 1
|
||||
if count == 32:
|
||||
if count == tools.ENCODINGS[encoding]:
|
||||
bitab.append(chr(buff))
|
||||
buff, count = 0, 0
|
||||
if bitab[-1] == ":" and limit == None:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue