Basic steganography algorithms and methods

Steganography is the art and science of writing hidden messages in such a way that no one, apart from the sender and intended recipient, suspects the existence of the message, a form ofsecurity through obscurity. The word steganography is of Greek origin and means “concealed writing” from the Greek words steganos (στεγανός) meaning “covered or protected”, and graphei(γραφή) meaning “writing”. The first recorded use of the term was in 1499 by Johannes Trithemius in his Steganographia, a treatise on cryptography and steganography disguised as a book on magic. Generally, messages will appear to be something else: images, articles, shopping lists, or some other covertext and, classically, the hidden message may be in invisible ink between the visible lines of a private letter.

The advantage of steganography over cryptography alone is that messages do not attract attention to themselves. Plainly visible encrypted messages—no matter how unbreakable—will arouse suspicion, and may in themselves be incriminating in countries where encryption is illegal. Therefore, whereas cryptography protects the contents of a message, steganography can be said to protect both messages and communicating parties.

What are the basic and simpliest steganography algorithms and methods? I mean the steganography applied to images.

I have written a library for this in the past a long time ago so I can describe the process.

Basically if you have a file format, let’s say the 24-bit BMP format. First you need a way to read and write pixels into that file format. Either you can use a library or write your own once you learnt what the file format is.

An image can be looked at as a series of pixels. Consider a 4×4 pixel image:

x x x x

x x x x

x x x x

x x x x

Number these pixels from 1 to 16:

01 02 03 04

05 06 07 08

09 10 11 12

13 14 15 16

Each pixel that is numbered above has a red component, a green component and a blue component. Each of those components are 1 byte each and so each component can be looked at as a value of 0 to 255. (24-bit = 8bits for red, 8 bits for green, 8 bits for blue). So each of the numbers above have 3 sets of values from 0 to 255.

So in the above example with a 4×4 image you have a total of 16pixels*3color_components = 48 bytes of data in your image. Typically what you will do is use only the least significant bit of each color component to encode your image. In which case you would have 48 bits bits of data available for you = 6 bytes available to you to encode any 6 byte message you want.

To make this easier though let’s just look at encoding a simple 3 bit message into a single pixel. And let’s assume we are only using 1 bit per color component. Let’s say we want to encode the 3 bit message: 111

Here is an example of the value pixel 1 above has before you encode the data:

R: 10101011

G: 11111010

B: 00011010

What you do is change only the least significant bit to the new data:

R: 1010101 1

G: 1111101 1

B: 0001101 1

The pixel will look the same to the human eye, but now you are using the least significant bit to represent the data you wanted to encode.

If you want to encode more than 3 bits of data into a single pixel you can also do that. What happens is that you will encode more than just the least significant bit, you can use the least 2 significant bits, or the least 3, etc. The more bits you use, you will start to notice a little bit of a difference in the image quality. You can use up to 7 bits though and your image will still look recognizable.

Typically you will have a lot more than 3 bits of data you want to encode though. The more data you want to encode, you will have to either have more pixels, or use more bits per pixel to encode the data. Let’s say you have 9 bits of data you want to encode, well if you are only using the least significant bit, then you need 3 pixels to encode that information. If you want to only use 1 pixel though you can do that by using the 3 least significant bits per color component to encode that data.

To do this type of work you’ll probably want to create some functions for easily working with bits of data that abstract away the complexities of dealing constantly with bitwise operators.

The technique will vary for different file formats, but the concept is the same. Steganography can also refer just to hiding the data for example in a GIF extension block even. Typically you hide it by varying the pixels of the image though, or in some file formats the color lookup table.

Some images have a color lookup table in the header, and then the pixels are indexes into those color lookup tables. What you can do is re-order the color lookup table so the most similar colors are close together, then you can encode data both into the color lookup table itself and into the indexes of the pixels. Because it won’t matter if the index slightly changes because the lookup table is ordered according to being similar.

You really do need to have an understanding of the file formats to do this type of work though. Or at least be using a library that can manipulate the file format and file data for you. If you are really interested in this topic I suggest to start with a simple file format like BMP and to learn it. You can always find file format specifications on sites like www.wotsit.org.

How does the program recognize the encrypted message in image without the source image?

You are correct. The program that decodes the information does not need the source image. How this works is that it simply does the reverse, the program will need to know how many bits of data you enoded using and use the same to decode. It will simply iterate over each pixel and combine the bits into bytes and write those bytes out to a file.