mirror of
https://github.com/cedricbonhomme/Stegano.git
synced 2025-05-12 17:18:30 +02:00
Improvements (speed) by Christophe.
This commit is contained in:
parent
04984d5e88
commit
c9417bddd0
2 changed files with 38 additions and 5 deletions
35
lsb-s.py
35
lsb-s.py
|
@ -24,7 +24,6 @@ def hide(img, message):
|
|||
|
||||
npixels = width * height
|
||||
if len(message_bits) > npixels * 3:
|
||||
print """Too long message (%s > %s).""" % (len(message_bits), npixels * 3)
|
||||
return """Too long message (%s > %s).""" % (len(message_bits), npixels * 3)
|
||||
|
||||
for row in range(height):
|
||||
|
@ -48,6 +47,40 @@ def hide(img, message):
|
|||
return encoded
|
||||
|
||||
def reveal(img):
|
||||
"""
|
||||
Find a message in an image
|
||||
(with the LSB technique).
|
||||
"""
|
||||
width, height = img.size
|
||||
buff, count = 0, 0
|
||||
bitab = []
|
||||
for row in range(height):
|
||||
for col in range(width):
|
||||
r, g, b = img.getpixel((col, row))
|
||||
|
||||
buff += (r&1)<<(7-count)
|
||||
count += 1
|
||||
if count == 8:
|
||||
bitab.append(chr(buff))
|
||||
buff, count = 0, 0
|
||||
|
||||
buff += (g&1)<<(7-count)
|
||||
count += 1
|
||||
if count == 8:
|
||||
bitab.append(chr(buff))
|
||||
buff, count = 0, 0
|
||||
|
||||
buff += (b&1)<<(7-count)
|
||||
count += 1
|
||||
if count == 8:
|
||||
bitab.append(chr(buff))
|
||||
buff, count = 0, 0
|
||||
|
||||
if len(bitab) > 0 and bitab[-1] == chr(126):
|
||||
return "".join(bitab)[:-1]
|
||||
return ""
|
||||
|
||||
def reveal_slow(img):
|
||||
"""
|
||||
Find a message in an image
|
||||
(with the LSB technique).
|
||||
|
|
|
@ -34,10 +34,10 @@ def steganalyse(img):
|
|||
|
||||
if __name__ == '__main__':
|
||||
# Point of entry in execution mode
|
||||
original_image_file = "./pictures/montenach.png"
|
||||
encoded_image_file = "./pictures/montenach_enc.png"
|
||||
original_image_file_steganalysed = "./pictures/montenach_steganalysed.png"
|
||||
encoded_image_file_steganalysed = "./pictures/montenach_enc_steganalysed.png"
|
||||
original_image_file = "./pictures/free.png"
|
||||
encoded_image_file = "./pictures/free_enc.png"
|
||||
original_image_file_steganalysed = "./pictures/free_steganalysed.png"
|
||||
encoded_image_file_steganalysed = "./pictures/free_enc_steganalysed.png"
|
||||
|
||||
img_original_image_file = Image.open(original_image_file)
|
||||
img_encoded_image_file = Image.open(encoded_image_file)
|
||||
|
|
Loading…
Add table
Reference in a new issue