Click here to Skip to main content
15,885,546 members
Articles / Desktop Programming / MFC
Article

Hiding a text file in a bmp file

Rate me:
Please Sign up or sign in to vote.
4.72/5 (348 votes)
26 Nov 20033 min read 493.7K   22.8K   206   124
How to hide a text file in a bmp file

Sample Image - hideit_SnapShoot.jpg

Introduction

I think all of us have dreamed of a secret language with our friends Image 2 , well this program simply hides any text file (can contain a secret message to any friend Image 3 ) in a bmp file . No one can feel or see any changes to the picture , and you then simply send this picture to your friend who  will use a certain password to recover the text file .

I hope you enjoy my program and please don't forget to vote for my program Image 4 . At last I want to say that it is my first time to put my programs in the internet and to put comments in the sources.

Background

Structure of text file:

Any text file consists of streams of characters , each character is 1 byte (ASCII code) each byte as all of us of course know consists of 8 bits .

text structure

The function which is used to convert the ASCII code (decimal) to the binary equivalent called CreateBinLookUpTable() , which simply creates an array as following :

bin[0]="00000000";
bin[1]="00000001";
..
..
bin[254]="11111110";
bin[255]="11111111"

There are many methods to convert from decimal to binary but I found this is from the fastest methods.

Bitmap file structure:

In general the bmp file consists in of two parts a header and the data part.

bmp struct

Logic operations:

In the c/c++ there is a bitwise operator ,one of these operators is the AND " & " , to see the AND operation look at the following table :

AND

How To change a certain bit in a byte using MASK:

if we have 'H' '0100 1001' and we want to change the last bit to 0 simply we ANDed 'H' with the mask 254 ('1111 1110) , the result will be '0100 1000' and if the last bit is '0' and we want to change it to 1 so we first ANDed with the same mask then add 1.

Using the code

Hiding the text in the bmp file technique:

  1. Reading the text file and converting each char. to 8 bits in array srcBin[].
  2. Reading the bmp file and ANDing each byte with the mask 254 '1111 1110'.
  3. Then adding to it 1 or not depending on the srcBin[] array.
  4. Saving the result back to the bmp file.
  5. Well since it is just one bit change in each byte so our eye never be able to see the such difference.

hiding diagram

Points of Interest

When you are going to try my demo ,you will find three pictures ,use them with the program using the password 'aaaaa' (take care it is CASE SENSTIVE) and read my msg to you Image 9 then vote for my work .

These samples pictures are in the demo and with the source in the release folder.

Now see the following the picture; can you see any difference between two pictures Image 10

Can u see any diff

Hey now one might ask if there is a way to know if this pic hold a msg inside it or not ?? Image 12 Well I found indeed one method ,I discovered it by chance but it can be used only for a black or a white image. This using the famous program 'Paint Shop Pro' ,there is something called 'Split to HSL' ,you will find a new image created called saturation .

Following image show us how my msg is hidden in the image Image 13

diff

Thanks a lot For Your Time. Don't forget to vote for my program Image 15

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Systems Engineer
Egypt Egypt
My Name Ahmed Osama.
Communication & Electronic engineering
I like so much programming using c\c++ , MFC and VC++
i like programming in many fields like "digital signal processor" and math and image processing

Comments and Discussions

 
GeneralMy vote of 4 Pin
do khac hieu4-Dec-10 18:44
do khac hieu4-Dec-10 18:44 
Generalneed documentation & idea Pin
a.hamza1-Nov-10 23:43
a.hamza1-Nov-10 23:43 
GeneralMy vote of 5 Pin
vk150621-Sep-10 18:01
vk150621-Sep-10 18:01 
Questionhey need documentation Pin
amitnaik2003-Sep-10 11:53
amitnaik2003-Sep-10 11:53 
AnswerRe: hey need documentation Pin
sheku hussain23-Sep-11 9:34
sheku hussain23-Sep-11 9:34 
QuestionCompilation Errors seen in the source code attached. Kindly help me out. Pin
speed_12331-May-10 0:51
speed_12331-May-10 0:51 
GeneralNice work Pin
ganesh.dp28-May-10 2:22
ganesh.dp28-May-10 2:22 
Generalimpressed..got my 5..but.. Pin
Omar Gameel Salem7-Feb-10 4:26
professionalOmar Gameel Salem7-Feb-10 4:26 
Generalwow Pin
konikula15-Dec-09 15:43
konikula15-Dec-09 15:43 
GeneralDoesnt work on WinXP Pro compiled with VC 8.0 Pin
Michael B Pliam9-Oct-09 13:58
Michael B Pliam9-Oct-09 13:58 
QuestionRe: Doesnt work on WinXP Pro compiled with VC 8.0 Pin
speed_12331-May-10 0:53
speed_12331-May-10 0:53 
Generalhi Pin
tvailpulli11-Sep-09 21:45
tvailpulli11-Sep-09 21:45 
Generalgood but it would be good to create a new bmp file rather than using same file as it cannot be recovered without text Pin
ashishshevale13-May-09 0:00
ashishshevale13-May-09 0:00 
Questionmore simple pls Pin
Yüksel ALBOY2-May-09 3:02
Yüksel ALBOY2-May-09 3:02 
Generalhi Pin
khushbu jain8-Mar-09 6:44
khushbu jain8-Mar-09 6:44 
Generalgood work Pin
nitin_24_200924-Feb-09 6:04
nitin_24_200924-Feb-09 6:04 
GeneralImage Steganography Pin
bluffmaster_aremachis14-Feb-09 7:58
bluffmaster_aremachis14-Feb-09 7:58 
Generalabout size of file Pin
indiraagandhi10-Dec-08 7:21
indiraagandhi10-Dec-08 7:21 
GeneralHi Pin
tnla25-Nov-08 8:47
tnla25-Nov-08 8:47 
Generalit's NICE Pin
Raghu_cyberdude21-Nov-08 18:42
Raghu_cyberdude21-Nov-08 18:42 
GeneralWOW Pin
Belerofonte29-Aug-08 9:40
Belerofonte29-Aug-08 9:40 
GeneralThanks Pin
Beyza30-Mar-08 11:30
Beyza30-Mar-08 11:30 
GeneralThnx Pin
ComputerEng0325-Mar-08 8:24
ComputerEng0325-Mar-08 8:24 
Generalmar7aba Eng Ahmad Pin
engkhlaif118-Mar-08 8:09
engkhlaif118-Mar-08 8:09 
Questionhow can i compile this code at my PC Pin
engkhlaif118-Mar-08 8:01
engkhlaif118-Mar-08 8:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.