Cleaner code. Added comments.

This commit is contained in:
cedricbonhomme 2010-10-05 19:11:17 +02:00
parent 5d00f6334b
commit bab294abae
5 changed files with 29 additions and 24 deletions

View file

@ -3,6 +3,7 @@
__author__ = "Cedric Bonhomme"
__version__ = "$Revision: 0.1 $"
__date__ = "$Date: 2010/10/01 $"
__license__ = "GPLv3"
from PIL import Image

View file

@ -4,6 +4,7 @@
__author__ = "Cedric Bonhomme"
__version__ = "$Revision: 0.1 $"
__date__ = "$Date: 2010/10/01 $"
__license__ = "GPLv3"
import sys

View file

@ -4,6 +4,7 @@
__author__ = "Cedric Bonhomme"
__version__ = "$Revision: 0.1 $"
__date__ = "$Date: 2010/10/01 $"
__license__ = "GPLv3"
from PIL import Image

View file

@ -4,6 +4,7 @@
__author__ = "Cedric Bonhomme"
__version__ = "$Revision: 0.1 $"
__date__ = "$Date: 2010/10/01 $"
__license__ = "GPLv3"
import operator
@ -36,21 +37,16 @@ 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"
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)
input_image_file = Image.open(options.input_image_file)
output_image = steganalyse(input_image_file)
soutput_image.save(options.output_image_file)

View file

@ -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)