Hiding information inside images
As a child, there was a game called secret message which consisted of writing something on a sheet of paper with lemon juice and handing it to a friend who knew that by holding a candle underneath, a message would be revealed — without any of the intermediaries ever knowing. We can say that this game was a form of steganography “Steganography (from the Greek ‘hidden writing’) is the study and use of techniques to conceal the existence of a message within another, a form of security through obscurity. In other words, steganography is the particular branch of cryptology that consists of disguising one piece of writing within another in order to mask its true meaning.” - Wikipedia Today I’m going to introduce another type of steganography — one that uses images to hide text inside pixels! An image is composed of pixels, and each pixel represents the smallest possible color point using N bits. The more bits per color, the more colors a pixel can represent. In my example I will focus only on 32-bit images ( RGBA or ARGB ) where 8 bits are used per color component. Obviously the technique is easily adaptable to other formats. What happens if I change a single bit of the red component of every pixel? Even with the original image side by side, we would be unable to notice the difference — only a hashing algorithm like SHA1 could tell the files apart. Therefore, I can use this same trick of altering pixels to hide a message inside the image, and only someone who knows the implementation will know how to extract the message. But to do this we need to separate each bit of the message and change only one or two bits of each color component. It sounds like very little space, but if we do the math, an 800×600 image — which is considered low resolution today — can hold 800 width _ 600 height = 480000 pixels 480000 pixels _ 4 components = 1920000 bits 1920000 bits / 8 = 240000 bytes In other words, we can fit a message of up to ~30 KB in an 800×600 image :) Remember, we are talking about pixels, not file size — that depends on the chosen format. And speaking of format, this only works with lossless formats. To achieve our goal we need to master the ancient art of bit twiddling . There is an excellent resource on the subject called: Bit Twiddling Hacks Writing a hidden message: Reading a hidden message from an image: The file size changed slightly due to the format used — in this case, PNG. This technique can be used to hide not only text, but also other images, sounds, or any kind of data. The source code can be found in this gist