Encoding a message...

Encoding a message…

The idea for this program came when I was reading an article about the lengths that spies in the second world war went to hide information.

It seemed that it would be interesting to hide some data in an image.

This image contains the string ‘Top secret message, not to be seen by anyone, guarded by ferocious snow hounds.’

 

The process used in this instance was to take a string; the secret message and transform that into a bit stream.

That bit stream is then encoded directly into the pixel data of an image.

Each pixel component (three per pixel; R,G & B)  is modified such that the least significant bit of the component maps to one of the bits in the bit stream.

This way, each pixel can encode 3 bits.

The resulting image is not perceptibly different from the original and without a pixel by pixel comparison between the original image and the processed image there is no way to tell that the image is holding a secret message.

For comparison, here is the original image.

The unaltered image.

The unaltered image.

There is no obvious sign that the image contains any midden message and the message can only be retrieved when interpreting the image data in a very specific manner.

In an image such as this, one that contains a natural scene, complete with noise, there is no practical way of determining wether or not this is a secret message or just a picture of some dogs.

To better illustrate the process, I have encoded a similar message into a completely black image.

“This is a super secret message that is to be encoded in a completely black image.”

A plain black image with an encoded message.

A plain black image with an encoded message.


Once again, there is no visible sign that the image contains a message, however because the image is one solid colour, if the image is run through a normalising filter, the tiny pixel variations are amplified. This gives a good visual representation of what exactly is happening.

This shows a magnified view of the top left corner of the normalised image.

Black Processed Equalised Snippet

Again; the only reason this is possible is because the image is one solid color, the same technique can not be applied to a more diverse image. Normalising the image of the dogs for example just results in an image with with a different colour balance and no evidence of pixel fiddling shenanigans.

 

 

One caveat with this method is that the message will not survive lossy compression, all the output files are compressed with the lossless PNG format.