From 7a5c23ef2fcdbd179db55bbdcc62344a5db9b161 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Bonhomme?= Date: Wed, 8 Mar 2017 22:26:12 +0100 Subject: [PATCH] Fixed #12. More tests to come. --- bin/lsb | 7 ------- setup.py | 2 +- stegano/tools.py | 12 +++++------- 3 files changed, 6 insertions(+), 15 deletions(-) diff --git a/bin/lsb b/bin/lsb index 0987852..973b13f 100755 --- a/bin/lsb +++ b/bin/lsb @@ -81,13 +81,6 @@ if arguments.command == 'hide': elif arguments.command == 'reveal': secret = lsb.reveal(arguments.input_image_file) if arguments.secret_binary != None: - """data = tools.base642binary(secret) - from PIL import Image - import io - file_like = io.BytesIO(data) - file_like.seek(0) - image = Image.open(file_like) - image.save(arguments.secret_binary)""" data = tools.base642binary(secret) with open(arguments.secret_binary, "wb") as f: f.write(data) diff --git a/setup.py b/setup.py index 2f1a59c..b8f5693 100644 --- a/setup.py +++ b/setup.py @@ -36,7 +36,7 @@ with open('CHANGELOG.rst', 'r') as f: setup( name='Stegano', - version='0.6.7', + version='0.6.8', author='Cédric Bonhomme', author_email='cedric@cedricbonhomme.org', packages=packages, diff --git a/stegano/tools.py b/stegano/tools.py index f36057e..a17be95 100755 --- a/stegano/tools.py +++ b/stegano/tools.py @@ -89,15 +89,13 @@ def binary2base64(binary_file): printable string. """ # Use mode = "rb" to read binary file - fin = open(binary_file, "rb") - binary_data = fin.read() - fin.close() - # Encode binary to base64 string (printable) - return base64.b64encode(binary_data) + with open(binary_file, "rb") as bin_file: + encoded_string = base64.b64encode(bin_file.read()) + return encoded_string.decode() def base642binary(b64_fname): """ Convert a printable file to a binary file. """ - b64_fname += b'===' - return base64.decodestring(b64_fname) + b64_fname += '===' + return base64.b64decode(b64_fname)