Click here to Skip to main content
11,923,948 members (61,925 online)
Click here to Skip to main content
Add your own
alternative version


64 bookmarked

Steganography III - Change only one Bit per Pixel

, 3 Apr 2004 CPOL
Rate this:
Please Sign up or sign in to vote.
An article about hiding each byte of a message bit-by-bit in eight pixels.

Sample Image - steganodotnet3.png


The application described in the last article Steganography II always added visible noise to the carrier bitmaps. This article is about splitting the bytes and hiding each bit in a different pixel. The hidden message is really invisible, because only the lowest bit of one color component is changed.


Before reading this, you should have read at least part one, Steganography - Hiding messages in the Noise of a Picture. This article uses the application described in part one and two, but you don't need the features added in part two to understand this one.

End of the rainbow

Replacing a whole byte of a RGB color produces a rainbow pattern. This is how a white image (all pixels just white) looks like after hiding a text message:

typical colour noise

On a colorful photo, these rainbow pixels may be alright. In grayscale mode, the same message in the same picture looks like this:

typical grayscale noise

As you can see, too many bits of the pixels have been changed. Now, we’re going to spread each byte over eight pixels and make the rainbow disappear.

Get and set bits

spreading a byte over eight pixels

For each byte of the message, we have to:

  1. Grab a pixel.
  2. Get the first bit of the message byte.
  3. Get one color component of the pixel.
  4. Get the first bit from the color component.
  5. If the color-bit is different from the message-bit, set/reset it.
  6. Do the same for the other seven bits.

The C#-functions for getting and setting single bits are simple:

private static bool GetBit(byte b, byte position){
	return ((b & (byte)(1 << position)) != 0);

private static byte SetBit(byte b, byte position, bool newBitValue){
	byte mask = (byte)(1 << position);
		return (byte)(b | mask);
		return (byte)(b & ~mask);

The rest of the code has not changed much. Hiding works like that now...

hide a message

...and extraction works like that:

extract a message

That's enough text for today. If you want to know the details, you should download the source.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Corinna John
Software Developer
Germany Germany
Corinna lives in Hannover/Germany (CeBIT City) and works as a Delphi developer, though her favorite language is C#.

You may also be interested in...

Comments and Discussions

GeneralRe: Steganografy in java Pin
Corinna John9-May-06 6:45
memberCorinna John9-May-06 6:45 
GeneralSteganografy in java Pin
rafaelvecchio9-May-06 3:46
memberrafaelvecchio9-May-06 3:46 
GeneralRe: Steganografy in java Pin
andre.fiap.br22-Mar-07 11:44
memberandre.fiap.br22-Mar-07 11:44 
GeneralRe: Steganografy in java Pin
chaitumad24-May-09 20:50
memberchaitumad24-May-09 20:50 
GeneralRe: Steganografy in java Pin
andre.fiap.br25-May-09 8:32
memberandre.fiap.br25-May-09 8:32 
GeneralVC6++ HELP HOW Pin
cnncnn18-Aug-04 21:20
membercnncnn18-Aug-04 21:20 
GeneralProblem with PNG Image Pin
lonelywind198221-Jun-04 23:09
memberlonelywind198221-Jun-04 23:09 
GeneralRe: Problem with PNG Image Pin
Corinna John22-Jun-04 21:31
memberCorinna John22-Jun-04 21:31 
In CryptUtility.SaveBitmap(), the image is copied into a new image.
If you want to keep the original color depth, you can comment out the following lines:
//copy the bitmap - comment this out
//Image img = new Bitmap(bitmap);

//close bitmap file - comment this out

//save new bitmap - change this

//img.Save(fileName, format);

bitmap.Save(fileName, format);

GeneralSetting pixel in Bitmap Object Pin
Alexsander Antunes4-Mar-04 7:23
memberAlexsander Antunes4-Mar-04 7:23 
GeneralRe: Setting pixel in Bitmap Object Pin
Corinna John4-Mar-04 21:16
memberCorinna John4-Mar-04 21:16 
GeneralRe: Setting pixel in Bitmap Object Pin
chaitumad24-May-09 20:50
memberchaitumad24-May-09 20:50 
GeneralGetBit/SetBit Pin
jmueller4-Nov-03 22:24
memberjmueller4-Nov-03 22:24 
GeneralRe: GetBit/SetBit Pin
Corinna John5-Nov-03 10:20
memberCorinna John5-Nov-03 10:20 
GeneralRe: GetBit/SetBit Pin
jmueller5-Nov-03 10:30
memberjmueller5-Nov-03 10:30 
GeneralRe: GetBit/SetBit Pin
Corinna John5-Nov-03 10:35
memberCorinna John5-Nov-03 10:35 
GeneralRe: GetBit/SetBit Pin
Corinna John4-Apr-04 22:56
memberCorinna John4-Apr-04 22:56 
Generalavi file Pin
unitecsoft6-Oct-03 9:25
memberunitecsoft6-Oct-03 9:25 
GeneralRe: avi file Pin
Corinna John6-Oct-03 20:38
memberCorinna John6-Oct-03 20:38 
GeneralRe: avi file Pin
Corinna John25-Oct-03 6:52
memberCorinna John25-Oct-03 6:52 

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.151125.3 | Last Updated 4 Apr 2004
Article Copyright 2003 by Corinna John
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid