Category Archives: Just programming

Steganography (or, how to be a secret agent)

Encryption is boring. No matter how many bits of AES you have, or how big of a prime number is keeping your super-secret data (or lolcat photos) secure, it’s still obvious that you have something to hide. That’s why the ancient Greeks invented steganography, the practice of hiding one message inside another. (Of course, they were sending messages about rebellion – not nearly as important as lolcats). Since its invention, steganography has been used to conceal messages in everything from a tattoo on someone’s head to the yarn in a sweater. Of course, this is all very cumbersome and time-consuming. Now enter the computer. A whole new medium to send secret messages! (and look at cat photos). Digital data provides an excellent opportunity to hide messages, because what a user sees when he opens, say, a picture, is very different from how the data is stored (in o’s and 1’s), and we can use this to our advantage. We can now examine how a digital image can be used to conceal text, or even other files (Disclaimer: I only use this to show off to friends. Now, be a good person and don’t do anything illegal with your new secret-agent powers, please! As Google used to say, don’t be evil!)

A digital image is made up of pixels, thousands or millions of solid-color points that together form an image. And the color of each pixel is represented by four digital values (red, green, blue and alpha), each of which is a binary byte. Now, the neat thing about binary numbers is that, they’re…well, binary. Each digit can only be a zero or a one, and each digit’s value, or weight, increases  as you go right to left. This means that the rightmost digit (least significant bit – LSB) in a binary number can only change a number by 1. And since an unsigned byte has a maximum value of 255, changing the LSB of a pixel can only change the brightness of the color of that pixel by 1/256, or  less than .4%. Ta-da! We now have a perfect place to hide our message. Furthermore, a normal digital photo contains (600 x 800 pixels * 4) 1,920,000 such LSBs, it is possible to hide almost a 2MB file in a normal image, and here’s how:

Just as a picture is stored as binary data on a computer, so is everything else. So, if we take the image we want to hide our message in, and replace each LSB in each byte of the picture with a bit from the file we want to hide, we get an image that looks identical, but now conceals a secret file.  This can be done in virtually any programming language, and is a really neat way to learn about digital data and encoding. Plus, now you can hide pictures of lolcats inside other pictures of lolcats! (lolcatception).

Unfortunately, there are people out there who use steganography for evil purposes. Don’t be one of them.

Happy new year!