This script hides files within images (currenlty PNG) and extracts the modified image to your disk.
The maximum file size that can be hidden inside an image depends on the size of the image.
max_file_size = (height_of_image * width_of_image * 6/8) bytes
"100k words.txt" is hidden in "original_image.png" called "image_with_100k words.png". Go and check if you can tell the difference between these two images. You can use this section to extract "100k words.txt" from "image_with_100k words.png".
Example of original image:
Modified image
This image has 100k words hidden inside!
How does it work;
It is based on a simple principle that if we change the LSB (Least Significant Bits) of each Pixel, then the change will not be significant and will not be observed with the naked eye.
So this section takes 2 bits of data from the file to hide and replaces the last 2 bits of one pixel with those 2 bits and then moves on to the next pixel.
The maximum change in pixels can be 4 units and the value range in PNG image (0,255), so this change is not significant.
In a PNG image, each pixel has 3 channels red, green and blue. (Some PNG images have 1 or 4 channels, but this program will convert them to 3 channels) A typical pixel in a PNG image looks like:
a_pixel = (17,32,11) # (RED, GREEN, BLUE)
So we can save 3 times 2 bits per Pixel, which means 6 bits per pixel. This takes us to the upper limit of the file size, which can be hidden in an image:
max_file_size = (height_of_image * width_of_image * 6/8) bytes
Let's understand it with an example. The data that will be hidden are:
binary_data = 0b100111
Let's take the first two bits and replace them with the RED Channel of our "a_pixel".
a_pixel = (0b10001, 0b100000, 0b1011) # binary representation of a_pixel values # Let's change a_pixel's RED Channel # 0b10001 -> 0b10010 (First 2 bits are 10) a_pixel = (0b10010, 0b100000, 0b1011) # modified pixel
Let's take 2 bits from binary_data again to replace the last 2 bits of GREEN Channel with them.
a_pixel = (0b10010, 0b100000, 0b1011) # Let's change a_pixel's GREEN Channel # 0b100000 -> 0b100001 (The 2 bits are 01) a_pixel = (0b10010, 0b100001, 0b1011) # modified pixel
Let's do it again with the BLUE Channel and we're done.
a_pixel = (0b10010, 0b100001, 0b1011) # Let's change a_pixel's BLUE Channel # 0b1011 -> 0b1011 (The 2 bits are 11); Notice that the value wasn't changed this time a_pixel = (0b10010, 0b100001, 0b1011) # pixel wasn't modified this time
So we have hidden a 6 bit message in one pixel. Let's look at the changes in the pixel
a_pixel = (0b10001, 0b100000, 0b1011) = (17, 32, 11) a_pixel_with_data = (0b10010, 0b100001, 0b1011) = (18, 33, 11)
As we can see that the change is not even noticeable at the pixel level. The Module does this repeatedly until all our data is stored in the image.
NOTE: The "noise" in the photo increases and if we use any photo editing software to compare it with the original image, then this image will have much more noise than the original image.

Very smart way to put messages in pictures !!!