EasyBMP C++ Bitmap Library

EasyBMP Code Sample: (Old) Steganography

Note:

This is an old version of my steganography page. Please click here for an updated steganographic technique.

Summary:

We present some basic examples of steganography: the hiding of information within an image. After giving some information on how to do it, we give source code that was developed with the EasyBMP library.

Intro:

Steganography is the process of hiding information within an image file in such a way that it is nearly indetectable. It should at least be indetectable to the human eye. Ideally, it should even be hard for a computer to detect the information without getting a lot of "false positives" when scanning many images.

Here are some sample images. Can you determine which ones have hidden information? (The greyscale and color images use different algorithms.)

ColorSample0 ColorSample3
ColorSample2 ColorSample1
GreySample1 GreySample3
GreySample2 GreySample0

Steganography is not encryption. The point isn't to make the information impossible to decrypt, but rather to hide the data in the middle of innocuous data. Usually, this is done by modifying the image pixels in some way, e.g., by slightly modifying the color of the pixels.

How it Works: Greyscale Images

Any character can be considered as a number N from 0 to 255. This means that we can expand it in base 4:

N = R1*43 + G1*42 + R2*4 + G2,

where R1, R2, G1, G2 range from 0 to 3. Any pixel is a (red,green,blue) triple. Suppose that pixel is in greyscale. Then the pixel is (A,A,A) for some A. So, we can overwrite the pixel with

( A - R1 , A - G1 , A)

and we can overwrite the next pixel (B,B,B) with

( B - R2 , B - G2 , B).

Since each red, and/or green channel is changed by no more than 3, the change in color is nearly imperceptible. Furthermore, because the blue channel is unchanged, we know the original greyscale value of every pixel, and so inverting this operation is trivial. (That is, it's easy to get the original data out of the image.

To make the information harder to detect, we can add some random noise to the greyscale image prior to embedding the data. In these images, I added noise that could vary as much as 9. With this level of noise, I have found that it is virtually impossible to visually detect the information embedded in the image.

How it Works: Color Images

Any character can be considered as a number N from 0 to 255. This means that we can expand it in base 3:

N = R1*35 + G1*34 + B1*33 + R2*32 + G2*31 + B3,

where R1, G1, B1, R2 G2, B2 range from 0 to 2. Any pixel is a (red,green,blue) triple. Suppose that pixel is (rr,gg,bb). Then we can replace the pixel's original remainder modulo 3 with the information data, overwriting the pixel with:

( rr - ( rr (mod 3)) + R1, gg - ( gg (mod 3) ) +G1, bb - ( bb (mod 3) ) + B1 ).

That is, we overwrite the pixel with:

( rr/3 + R1, gg/3 + G1, bb/3 + B1 ),

where any m/3 denotes the largest multiple of 3 that does not exceed m.

Next, we do the same with the next pixel (rrr,ggg,bbb), overwriting the pixel with

( rrr/3 + R2, ggg/3 + G2, bbb/3 + B2 ).

To extract the information, all we need to know is that for each of the color channels,

<pixel data> (mod 3) = <information data>.

For instance, suppose a pixel has value (r,g,b) in an image containing embedded information. Then

r (mod 3) = R1 or r (mod 3) = R2.

This process can be used on the red, green, and blue channels of all the pixels to extract the information.

Because any red, green, or blue channel datum is changed by no more than 2, the information is extremely hard to see. Furthermore, this technique has the advantage that it does not require a conversion of the image into greyscale, so the images can be even more innocuous. However, there is a downside, too. Since the images data always has its remainder (mod 3) subtracted off before embedding information, it would be nearly pointless to add noise, since much of it would be subtracted off. (We'd have to add noise that was always bigger than 3 to have any effect.) So, it's difficult to further camouflage the data.

Source Code and Demo Programs:

I used the EasyBMP library to write these algorithms. It only took an hour or so to formulate and write the original version of the greyscale steganography program. (And then some tweaking and debugging time.) Likewise for the color versions. All downloads below include the source code (of course!) and executables for win32. Because EasyBMP is cross-platform compatible, these compile just fine under Linux, too. :-)

File Description License Posted
Stego.zip Original greyscale steganography program GPL 5-18-2005
Stego2.zip Newest greyscale steganography program (used above) GPL 5-18-2005
Stego3.zip Color steganography program GPL 5-18-2005

Usage:

For any program, type [program name] --help to get full help information and usage. For instance,

Stego3 --help

I'll give information on how to use the Stego3 program to embed a file into an image:

Stego3 -e sometext.txt original.bmp output.bmp

To get the text back out, do:

Stego3 -d somefile.bmp output.txt

That's it!

Some Last Information

These programs are provided for fun and personal use only and to demonstrate the basic ideas of steganography. They certainly aren't secure, and you shouldn't rely upon them for security. Furthermore, they aren't intended for use in conducting illegal activity. I have no doubt that folks at the NSA and elsewhere could detect and extract the information in these images very easily, and so I wouldn't even think about doing something illicit with them!!