From c9417bddd0680a4942a05914f40c3853a6a74e38 Mon Sep 17 00:00:00 2001 From: cedricbonhomme Date: Tue, 5 Oct 2010 10:52:02 +0200 Subject: [PATCH] Improvements (speed) by Christophe. --- lsb-s.py | 35 ++++++++++++++++++++++++++++++++++- steganalysis-parity.py | 8 ++++---- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/lsb-s.py b/lsb-s.py index 65f9d8a..92b0d76 100755 --- a/lsb-s.py +++ b/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). diff --git a/steganalysis-parity.py b/steganalysis-parity.py index 9e70a3b..48fb7ee 100644 --- a/steganalysis-parity.py +++ b/steganalysis-parity.py @@ -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)