From bab294abaef0a51748b2346f4e86a051680e0f94 Mon Sep 17 00:00:00 2001 From: cedricbonhomme Date: Tue, 5 Oct 2010 19:11:17 +0200 Subject: [PATCH] Cleaner code. Added comments. --- basic.py | 1 + lsb-s.py | 3 ++- steganalysis-parity.py | 1 + steganalysis-statistics.py | 32 ++++++++++++++------------------ tools.py | 16 +++++++++++----- 5 files changed, 29 insertions(+), 24 deletions(-) diff --git a/basic.py b/basic.py index d8a05aa..12fcd81 100755 --- a/basic.py +++ b/basic.py @@ -3,6 +3,7 @@ __author__ = "Cedric Bonhomme" __version__ = "$Revision: 0.1 $" __date__ = "$Date: 2010/10/01 $" +__license__ = "GPLv3" from PIL import Image diff --git a/lsb-s.py b/lsb-s.py index 5f49b42..55ff4ba 100755 --- a/lsb-s.py +++ b/lsb-s.py @@ -4,6 +4,7 @@ __author__ = "Cedric Bonhomme" __version__ = "$Revision: 0.1 $" __date__ = "$Date: 2010/10/01 $" +__license__ = "GPLv3" import sys @@ -117,7 +118,7 @@ if __name__ == '__main__': parser.add_option("-s", "--secret", dest="secret", help="Your secret (Message, Image, Music or any binary file.)") parser.set_defaults(input_image_file = './pictures/Lenna.png', - output_image_file = './pictures/Lenna_enc.png', + output_image_file = './pictures/Lenna_enc.png', secret = 'Hello World!') (options, args) = parser.parse_args() diff --git a/steganalysis-parity.py b/steganalysis-parity.py index b1e25ca..55001ba 100644 --- a/steganalysis-parity.py +++ b/steganalysis-parity.py @@ -4,6 +4,7 @@ __author__ = "Cedric Bonhomme" __version__ = "$Revision: 0.1 $" __date__ = "$Date: 2010/10/01 $" +__license__ = "GPLv3" from PIL import Image diff --git a/steganalysis-statistics.py b/steganalysis-statistics.py index b1c210b..5efecec 100644 --- a/steganalysis-statistics.py +++ b/steganalysis-statistics.py @@ -4,6 +4,7 @@ __author__ = "Cedric Bonhomme" __version__ = "$Revision: 0.1 $" __date__ = "$Date: 2010/10/01 $" +__license__ = "GPLv3" import operator @@ -35,22 +36,17 @@ def steganalyse(img): return dict_colours.keys()[:30], most_common 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" + # Point of entry in execution mode. + from optparse import OptionParser + parser = OptionParser() + parser.add_option("-i", "--input", dest="input_image_file", + help="Image file") + parser.add_option("-o", "--output", dest="output_image_file", + help="Image file") + parser.set_defaults(input_image_file = './pictures/Lenna.png', + output_image_file = './pictures/Lenna_steganalysed.png') + (options, args) = parser.parse_args() - img_original_image_file = Image.open(original_image_file) - img_encoded_image_file = Image.open(encoded_image_file) - img_original_image_file_steganalysed = Image.open(original_image_file_steganalysed) - img_encoded_image_file_steganalysed = Image.open(encoded_image_file_steganalysed) - - print steganalyse(img_original_image_file) - print - print steganalyse(img_encoded_image_file) - print - print - print steganalyse(img_original_image_file_steganalysed) - print - print steganalyse(img_encoded_image_file_steganalysed) \ No newline at end of file + input_image_file = Image.open(options.input_image_file) + output_image = steganalyse(input_image_file) + soutput_image.save(options.output_image_file) \ No newline at end of file diff --git a/tools.py b/tools.py index cc152b4..7c38b04 100755 --- a/tools.py +++ b/tools.py @@ -1,6 +1,10 @@ #! /usr/local/bin/python # -*- coding: utf-8 -*- +__author__ = "Cedric Bonhomme" +__version__ = "$Revision: 0.1 $" +__date__ = "$Date: 2010/10/01 $" +__license__ = "GPLv3" def a2bits(chars): """ @@ -58,13 +62,15 @@ def n_at_a_time(items, n, fillvalue): def binary2base64(binary_file, output_file): """ + Convert a binary file (OGG, executable, etc.) to a + printable file. """ - # use mode = "rb" to read binary file + # Use mode = "rb" to read binary file fin = open(binary_file, "rb") binary_data = fin.read() fin.close() - # encode binary to base64 string (printable) + # Encode binary to base64 string (printable) b64_data = base64.b64encode(binary_data) fout = open(output_file, "w") @@ -73,11 +79,11 @@ def binary2base64(binary_file, output_file): def base642binary(b64_fname): """ + Convert a printable file to a binary file. """ - # read base64 string + # Read base64 string fin = open(b64_fname, "r") b64_str = fin.read() fin.close() - - # decode base64 string to original binary sound object + # Decode base64 string to original binary sound object return base64.b64decode(b64_str) \ No newline at end of file