Click here to Skip to main content
12,626,219 members (29,064 online)
Click here to Skip to main content
Add your own
alternative version

Stats

381.7K views
19.9K downloads
201 bookmarked
Posted

Hiding a text file in a bmp file

, 26 Nov 2003
Rate this:
Please Sign up or sign in to vote.
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 https://www.codeproject.com/script/images/smiley_smile.gif , well this program simply hides any text file (can contain a secret message to any friend https://www.codeproject.com/script/images/smiley_smile.gif ) 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 https://www.codeproject.com/script/images/smiley_smile.gif . 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 https://www.codeproject.com/script/images/smiley_smile.gif 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 https://www.codeproject.com/script/images/smiley_smile.gif

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 ?? https://www.codeproject.com/script/images/smiley_smile.gif 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 https://www.codeproject.com/script/images/smiley_smile.gif

diff

Thanks a lot For Your Time. Don't forget to vote for my program https://www.codeproject.com/script/images/smiley_smile.gif

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

Share

About the Author

Just_Done
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

You may also be interested in...

Comments and Discussions

 
QuestionWonderful encryption Pin
Member 1269053018-Aug-16 3:39
memberMember 1269053018-Aug-16 3:39 
QuestionAMAZING Pin
Member 113912216-Apr-15 22:13
memberMember 113912216-Apr-15 22:13 
Generalthanks for every thing Pin
ame1319-Feb-14 4:45
memberame1319-Feb-14 4:45 
GeneralMy vote of 1 Pin
1709901743-Oct-13 4:43
member1709901743-Oct-13 4:43 
GeneralMy vote of 4 Pin
Riffa23-Sep-13 7:31
memberRiffa23-Sep-13 7:31 
GeneralMy vote of 4 Pin
Jay Ravikumar16-Sep-13 7:28
memberJay Ravikumar16-Sep-13 7:28 
Questionthanks Pin
rjtioe27-Aug-13 19:35
memberrjtioe27-Aug-13 19:35 
Generalthanks. Pin
ngotridat9220-Aug-13 7:26
memberngotridat9220-Aug-13 7:26 
Questiongreat Pin
Member 1020715713-Aug-13 6:18
memberMember 1020715713-Aug-13 6:18 
Questionassalamu alikum Pin
shabeer ahamed23-Jul-13 10:44
membershabeer ahamed23-Jul-13 10:44 
GeneralMy vote of 5 Pin
sukumarchandran28-Jan-13 19:22
membersukumarchandran28-Jan-13 19:22 
GeneralMy vote of 5 Pin
saikatdutta199128-Nov-12 8:24
membersaikatdutta199128-Nov-12 8:24 
QuestionTeslam edak Pin
MoDy kareem26-Nov-12 7:50
memberMoDy kareem26-Nov-12 7:50 
Questionthanks Pin
Member 961031718-Nov-12 19:28
memberMember 961031718-Nov-12 19:28 
GeneralMy vote of 5 Pin
kimtinh291616-Nov-12 7:32
memberkimtinh291616-Nov-12 7:32 
GeneralMy vote of 5 Pin
asquare2513-Oct-12 6:33
memberasquare2513-Oct-12 6:33 
Questionthanks Pin
Nikhil Uppada4-Sep-12 2:33
memberNikhil Uppada4-Sep-12 2:33 
QuestionMy vote of 5 Pin
ruiwng30-Aug-12 7:03
memberruiwng30-Aug-12 7:03 
GeneralMy vote of 5 Pin
Mukit, Ataul11-May-12 20:16
memberMukit, Ataul11-May-12 20:16 
GeneralMy vote of 5 Pin
dknaoremcha19-Mar-12 5:49
memberdknaoremcha19-Mar-12 5:49 
GeneralMy vote of 5 Pin
Phheoniix6-Dec-11 12:48
memberPhheoniix6-Dec-11 12:48 
GeneralMy vote of 5 Pin
isupercar23-Aug-11 18:39
memberisupercar23-Aug-11 18:39 
GeneralI need your help Pin
hadestaboo5-Jun-11 11:46
memberhadestaboo5-Jun-11 11:46 
GeneralRe: I need your help Pin
Member 1163431922-Apr-15 15:16
memberMember 1163431922-Apr-15 15:16 
GeneralMy vote of 4 Pin
do khac hieu4-Dec-10 19:44
memberdo khac hieu4-Dec-10 19:44 

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.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.161205.3 | Last Updated 27 Nov 2003
Article Copyright 2003 by Just_Done
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid