kelvins / steganography

:see_no_evil: Steganography: Hiding an image inside another
https://goo.gl/6u15mZ
MIT License
347 stars 86 forks source link

bug parsing arguments #1

Closed scgbckbone closed 6 years ago

scgbckbone commented 6 years ago

Hi, In your main function, when you parsing the args - you have to store:

vars(ap.parse_args()

into variable 'args' if you subsequently want to use it as a dict. So do this instead:

args = vars(ap.parse_args()

of even better (but be careful, now 'args' is not a dict but namespace object):

args = ap.parse_args()

then you can access values in namespace object as follows:

args.input_image1 args.input_image2 args.output_image

scgbckbone commented 6 years ago

also your unmerge function does not work (for now I do not have time to dig in) [attached is result picture test1 ]

kelvins commented 6 years ago

Hello @scgbckbone

The arguments parsing is a bug, I will fix it.

About the unmerge function, based on the image you shared, it seems you are trying to unmerge the original image. Perhaps you passed the original image as parameter instead of the merged image. Can you check it, please? Thanks

scgbckbone commented 6 years ago

Not sure how it can possibly work for you (without converting args to a dict). When you try to access your args as a dict, but have a list instead - you have to end up with TypeError steg_err

scgbckbone commented 6 years ago

I double checked and I'm doing it right - but ending up with the same image that I posted yesterday. What is your os? python?

kelvins commented 6 years ago

I’m not with my PC right now, but I will take a look on it as soon as possible. I’m using Mac OS Sierra with Python 2.7. This is actually weird, but it worked on my experiments. Thanks again.

scgbckbone commented 6 years ago

I tried with both 2.7 and 3.5 -> same results. My os is Ubuntu 16.04.4

kelvins commented 6 years ago

Hello @scgbckbone, sorry for the delay.

About the arguments parsing, it was actually a bug. As you have explained, I was trying to access it as a dictionary when it was actually a list. In the previous version, when I have generated the merged images (shown in the README) it was correctly implemented, then I change it for some reason (don't know why) and made that stupid mistake. Anyway, I have fixed it in the following commit:

About the other issue, related to unmerge the image: I have tested it using the PNG format (for the output image) and it worked as expected, but when trying to use the JPG format, it does not work and generates the same image you posted.

I will have to dig deeper to find out what is happening with the JPG format, but for now, it is possible to use the PNG format, for example:

$ python steganography.py --input_image1 res/image1.jpg \
                          --input_image2 res/image2.jpg \
                          --output_image res/merged_image.png

$ python steganography.py --input_image1 res/merged_image.png \
                          --output_image res/unmerged_image.png

Lastly, if you have some idea about why this is not working with JPG format, please let me know.

Thank you so much

kelvins commented 6 years ago

Since this issue is related to two distinct bugs, and the 'parsing arguments' bug was already fixed, I will create a new issue to report the bug related to the unmerge function with JPG image formats.

kelvins commented 6 years ago

Bug trying to unmerge images with JPG format

sleekmike commented 6 years ago

Please how do I get to open images; the program runs fine but I don't know to input images

Sent from my iPhone

On 2 Apr 2018, at 4:46 AM, Kelvin S. do Prado notifications@github.com wrote:

Since this issue is related to two distinct bugs, and the 'parsing arguments' bug was already fixed, I will create a new issue to report the bug related to the unmerge function with JPG image formats.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

scgbckbone commented 6 years ago

I double checked and now it works correctly with either python2 or python3.

Lastly, if you have some idea about why this is not working with JPG format, please let me know.

to be honest, I have no idea

kelvins commented 6 years ago

@sleekmike, you can call the script from the command line, as follows:

$ python steganography.py --input_image1 res/image1.jpg \
                          --input_image2 res/image2.jpg \
                          --output_image res/merged_image.png

$ python steganography.py --input_image1 res/merged_image.png \
                          --output_image res/unmerged_image.png

To use the Steganography class in your Python code, you need to use the Image module from the Pillow library, for example:

from PIL import Image

img1 = Image.open(input_image1)
img2 = Image.open(input_image2)

merged_image = Steganography.merge(img1, img2)
merged_image.save(output_image)
disarticulate commented 6 years ago

I've been looking into this.

You cannot use the JPG format for LSB or really any encoding, because the compression is lossy, therefore all bits will disappear when the function tries to resassmble.

See: http://domnit.org/stepic/doc/ https://pypi.python.org/pypi/cryptosteganography/0.2.1 https://github.com/RobinDavid/LSB-Steganography

There's a possibility of encoding without decompression here: http://www.ifs.schaathun.net/pysteg/