Thursday, October 27, 2005

Hide Text in Bitmap

You can easily hide a text message inside a Bitmap by altering the header.This is extremely easy than hiding the message by altering the LSB for each byte in the bitmap data.

lemme explain how this can be done.

Bitmap contains two headers (other than the optional colormap) namely ,BitmapFileHeader, and BitmapInfoHeader.We needn't care about second one ,all we care is the the first header, BitmapFileHeader.First 14 bytes of bitmap makes up the BitmapFileHeader whose structure can be shown as below

Type2 BytesSpecifies the file type, must be BM
File Size4 BytesSpecifies size of the file in bytes
Reserved2 BytesReserved; must be zero
Reserved2 BytesReserved; must be zero
Offset4 BytesSpecifies the offset, in bytes, from the beginning of FILEHEADER to the bitmap bits

It is the File Size and Offset Values that we are intersted in.Lets Consider an example of bitmap file

Type.
File SizeX
Reserved.
Reserved.
OffsetY

As seen in figure the size of file is X and the offset value is Y.Now, what we actually do is that we will insert the message right after the header block and before the bitmap Bits.

Type.
File SizeX + Size of message
Reserved.
Reserved.
MessageSecret
OffsetY + Size of message

As you can see , we have also increased the size of file and offset value to accomodate the message.

Thats it !!!! We have hidden a secret message inside a Bitmap. Isn't it simple ???
You can find a C# implementation of my code in planet-source-code.com.