Image steganography

Image steganography

Image steganography in python

What is steganography

Image Steganography is the process of hiding information which can be text, image or video inside a cover image. The secret information is hidden in a way that it not visible to the human eyes.


The intention is to hide any kind of data (in this demonstration we are using text) in a picture using the fact that a phot is only an interpretation of pixels (3-value type of data)


Suppose that the message we want to hide is “Hello”, since the message made of 5 byte, the pixels required for the encoding are 3·5=15, so a 4x4 image will be good to hide that kind of information

H = 72 = 01001000
e = 101 = 01100101
l = 108 = 01101100
o = 111 = 01101111

Now take a random 4x3 image made like this (total of 12 pixels):


Now, to encode the message pick the binary encoding of the letter and if the number is 1 change the number to odd, if its a 0 change the number to an even Let’s make an example with the H:

  • Take the binary in group of the letter (‘H’ in this case): 01001000
  • Pick the first 3 pixels of the image: (86,23,54),(12,53,85),(132,22,210)
  • Create the new pixels with the method descripted:

Do the same thing for all the letter


How to decode the data?

When the image is put in the decoder, it will controll every pixel, if the number is odd then it’s a 1, if it’s even a 0, then all will be reconverted from binary to normal text

Before encoding ‘hello’

img before enc

After encoding ‘hello’

img after enc

*** You can find all the code in my repo! ***