mirror of
https://github.com/cedricbonhomme/Stegano.git
synced 2025-05-12 17:18:30 +02:00
Cleaner code. Added comments.
This commit is contained in:
parent
5d00f6334b
commit
bab294abae
5 changed files with 29 additions and 24 deletions
1
basic.py
1
basic.py
|
@ -3,6 +3,7 @@
|
||||||
__author__ = "Cedric Bonhomme"
|
__author__ = "Cedric Bonhomme"
|
||||||
__version__ = "$Revision: 0.1 $"
|
__version__ = "$Revision: 0.1 $"
|
||||||
__date__ = "$Date: 2010/10/01 $"
|
__date__ = "$Date: 2010/10/01 $"
|
||||||
|
__license__ = "GPLv3"
|
||||||
|
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
|
|
3
lsb-s.py
3
lsb-s.py
|
@ -4,6 +4,7 @@
|
||||||
__author__ = "Cedric Bonhomme"
|
__author__ = "Cedric Bonhomme"
|
||||||
__version__ = "$Revision: 0.1 $"
|
__version__ = "$Revision: 0.1 $"
|
||||||
__date__ = "$Date: 2010/10/01 $"
|
__date__ = "$Date: 2010/10/01 $"
|
||||||
|
__license__ = "GPLv3"
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
@ -117,7 +118,7 @@ if __name__ == '__main__':
|
||||||
parser.add_option("-s", "--secret", dest="secret",
|
parser.add_option("-s", "--secret", dest="secret",
|
||||||
help="Your secret (Message, Image, Music or any binary file.)")
|
help="Your secret (Message, Image, Music or any binary file.)")
|
||||||
parser.set_defaults(input_image_file = './pictures/Lenna.png',
|
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!')
|
secret = 'Hello World!')
|
||||||
|
|
||||||
(options, args) = parser.parse_args()
|
(options, args) = parser.parse_args()
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
__author__ = "Cedric Bonhomme"
|
__author__ = "Cedric Bonhomme"
|
||||||
__version__ = "$Revision: 0.1 $"
|
__version__ = "$Revision: 0.1 $"
|
||||||
__date__ = "$Date: 2010/10/01 $"
|
__date__ = "$Date: 2010/10/01 $"
|
||||||
|
__license__ = "GPLv3"
|
||||||
|
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
__author__ = "Cedric Bonhomme"
|
__author__ = "Cedric Bonhomme"
|
||||||
__version__ = "$Revision: 0.1 $"
|
__version__ = "$Revision: 0.1 $"
|
||||||
__date__ = "$Date: 2010/10/01 $"
|
__date__ = "$Date: 2010/10/01 $"
|
||||||
|
__license__ = "GPLv3"
|
||||||
|
|
||||||
import operator
|
import operator
|
||||||
|
|
||||||
|
@ -35,22 +36,17 @@ def steganalyse(img):
|
||||||
return dict_colours.keys()[:30], most_common
|
return dict_colours.keys()[:30], most_common
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
# Point of entry in execution mode.
|
# Point of entry in execution mode.
|
||||||
original_image_file = "./pictures/montenach.png"
|
from optparse import OptionParser
|
||||||
encoded_image_file = "./pictures/montenach_enc.png"
|
parser = OptionParser()
|
||||||
original_image_file_steganalysed = "./pictures/montenach_steganalysed.png"
|
parser.add_option("-i", "--input", dest="input_image_file",
|
||||||
encoded_image_file_steganalysed = "./pictures/montenach_enc_steganalysed.png"
|
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)
|
input_image_file = Image.open(options.input_image_file)
|
||||||
img_encoded_image_file = Image.open(encoded_image_file)
|
output_image = steganalyse(input_image_file)
|
||||||
img_original_image_file_steganalysed = Image.open(original_image_file_steganalysed)
|
soutput_image.save(options.output_image_file)
|
||||||
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)
|
|
16
tools.py
16
tools.py
|
@ -1,6 +1,10 @@
|
||||||
#! /usr/local/bin/python
|
#! /usr/local/bin/python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
__author__ = "Cedric Bonhomme"
|
||||||
|
__version__ = "$Revision: 0.1 $"
|
||||||
|
__date__ = "$Date: 2010/10/01 $"
|
||||||
|
__license__ = "GPLv3"
|
||||||
|
|
||||||
def a2bits(chars):
|
def a2bits(chars):
|
||||||
"""
|
"""
|
||||||
|
@ -58,13 +62,15 @@ def n_at_a_time(items, n, fillvalue):
|
||||||
|
|
||||||
def binary2base64(binary_file, output_file):
|
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")
|
fin = open(binary_file, "rb")
|
||||||
binary_data = fin.read()
|
binary_data = fin.read()
|
||||||
fin.close()
|
fin.close()
|
||||||
|
|
||||||
# encode binary to base64 string (printable)
|
# Encode binary to base64 string (printable)
|
||||||
b64_data = base64.b64encode(binary_data)
|
b64_data = base64.b64encode(binary_data)
|
||||||
|
|
||||||
fout = open(output_file, "w")
|
fout = open(output_file, "w")
|
||||||
|
@ -73,11 +79,11 @@ def binary2base64(binary_file, output_file):
|
||||||
|
|
||||||
def base642binary(b64_fname):
|
def base642binary(b64_fname):
|
||||||
"""
|
"""
|
||||||
|
Convert a printable file to a binary file.
|
||||||
"""
|
"""
|
||||||
# read base64 string
|
# Read base64 string
|
||||||
fin = open(b64_fname, "r")
|
fin = open(b64_fname, "r")
|
||||||
b64_str = fin.read()
|
b64_str = fin.read()
|
||||||
fin.close()
|
fin.close()
|
||||||
|
# Decode base64 string to original binary sound object
|
||||||
# decode base64 string to original binary sound object
|
|
||||||
return base64.b64decode(b64_str)
|
return base64.b64decode(b64_str)
|
Loading…
Add table
Reference in a new issue