Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I hide a file inside an image with Python?

I know it's possible in Batch using the 'copy' command with the '/B' switch, i.e.:

copy /B imagefile+hiddenfile newfile

My question is this; Is it possible to do this in Python, and if so, how?

This question is very similar, and it's answer is acceptable, but I am still curious;

Is there a way to do this without the stepic module?

like image 235
mickdekkers Avatar asked Mar 23 '23 10:03

mickdekkers


2 Answers

You don't need stepic for that.

>>> out = file("out.jpg", "wb")
>>> out.write(file("someimage.jpg", "rb").read())
>>> out.write(file("somehiddenfile.pdf", "rb").read())
>>> out.close()

stepic is something completely different it is for putting "really" hidden data into an image, whereas your copy approach (and also my snippet above) just appends the file after the image's data. It is quite easy to extract the "somehiddenfile.pdf" from the generated file, whereas extracting steganographic information out of a real image is a lot more difficult.

like image 77
mawimawi Avatar answered Apr 25 '23 05:04

mawimawi


stepic is a python package written to perform this operation - why not simply look at the source?

like image 20
Sajjan Singh Avatar answered Apr 25 '23 06:04

Sajjan Singh