From 5d00f6334b793e8bb0effe21ce9102ff56465482 Mon Sep 17 00:00:00 2001 From: cedricbonhomme Date: Tue, 5 Oct 2010 19:03:38 +0200 Subject: [PATCH] Added command line for steganalysis-parity.py and basic.py. --- basic.py | 36 ++++++++++++++++++++++-------------- lsb-s.py | 5 +++-- steganalysis-parity.py | 26 +++++++++++++------------- 3 files changed, 38 insertions(+), 29 deletions(-) diff --git a/basic.py b/basic.py index 68ec9fe..d8a05aa 100755 --- a/basic.py +++ b/basic.py @@ -61,19 +61,27 @@ def reveal(img): if __name__ == '__main__': # Point of entry in execution mode - original_image_file = "./pictures/Lenna.png" - encoded_image_file = "./pictures/Lenna_enc.png" - # at this point don't exceed 255 characters - secret_message = "Parce que je le vaut bien!" + from optparse import OptionParser + usage = "usage: %prog hide|reveal [options]" + parser = OptionParser(usage) + 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.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', + secret = 'Hello World!') - img1 = Image.open(original_image_file) - img_encoded = hide(img1, secret_message) + (options, args) = parser.parse_args() - if img_encoded: - # Save it - img_encoded.save(encoded_image_file) - # Test it - img2 = Image.open(encoded_image_file) - print reveal(img2) - else: - print("text too long! (don't exeed 255 characters)") \ No newline at end of file + + if sys.argv[1] == "hide": + img = Image.open(options.input_image_file) + img_encoded = hide(img, options.secret) + img_encoded.save(options.output_image_file) + + elif sys.argv[1] == "reveal": + img = Image.open(options.input_image_file) + print reveal(img) \ No newline at end of file diff --git a/lsb-s.py b/lsb-s.py index 03a275b..5f49b42 100755 --- a/lsb-s.py +++ b/lsb-s.py @@ -108,7 +108,8 @@ def reveal_slow(img): if __name__ == '__main__': # Point of entry in execution mode. from optparse import OptionParser - parser = OptionParser() + usage = "usage: %prog hide|reveal [options]" + parser = OptionParser(usage) parser.add_option("-i", "--input", dest="input_image_file", help="Image file") parser.add_option("-o", "--output", dest="output_image_file", @@ -127,6 +128,6 @@ if __name__ == '__main__': img_encoded = hide(img, options.secret) img_encoded.save(options.output_image_file) - if sys.argv[1] == "reveal": + elif sys.argv[1] == "reveal": img = Image.open(options.input_image_file) print reveal(img) \ No newline at end of file diff --git a/steganalysis-parity.py b/steganalysis-parity.py index 48fb7ee..b1e25ca 100644 --- a/steganalysis-parity.py +++ b/steganalysis-parity.py @@ -34,16 +34,16 @@ def steganalyse(img): if __name__ == '__main__': # Point of entry in execution mode - 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) - - img_original_image_steganalysde = steganalyse(img_original_image_file) - img_encoded_image_steganalysed = steganalyse(img_encoded_image_file) - - img_original_image_steganalysde.save(original_image_file_steganalysed) - img_encoded_image_steganalysed.save(encoded_image_file_steganalysed) \ No newline at end of file + 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() + + input_image_file = Image.open(options.input_image_file) + output_image = steganalyse(input_image_file) + output_image.save(options.output_image_file) \ No newline at end of file