Hide Secret Message Inside an Image Using LSB-Steganography

March 7, 2018 | Views: 22040

Begin Learning Cyber Security for FREE Now!

FREE REGISTRATIONAlready a Member Login Here


Imagine a scenario where we want to send a confidential message and don’t want anyone except the recipient to read it. We will use every possible methods to make our message hidden from any third person. So here i am going to use LSB-Steganography method to hide our message inside an image.


What is LSB 

image source 

Least Significant bit also called RightMost Bit is a lowest bit of a binary number. For example in binary number 10010010, “0”is the least significant bit. 


What is LSB-Steganography 


image source

LSB-Steganography is a steganography technique in which we hide messages inside an image by replacing Least significant bit of image with the bits of message to be hidden.  


By modifying only the first most right bit of an image we can insert our secret message and it also make the picture unnoticeable, but if our message is too large it will start modifying the second right most bit and so on and an attacker can notice the changes in picture.


Let’s hide our message

STEP 1 Before hiding our secret message we will make sure to make it fully encrypted so if someone extracted the message from the image he would not able to get the secret message. So first we will create our secret key, for this i will open nano (you can use whatever you want ) by typing nano file.txt then press return and then i will enter my secret key then exit.



STEP 2  We will encrypt our message with symmetric key algorithm using gpg so that both the sender and receiver will only need a single key for encryption and decryption . So type gpg -c msg.txt to encrypt it. ( I am using CAST 128 cipher for encryption.)


STEP 3 It will ask for password so enter your desire password.



STEP 4 I will upload this encrypted message to some hosting server and then copy the downloadable link to hide it in our image.


STEP 5 Now type got clone https://github.com/RobinDavid/LSB-steganography.git and move into this directory.


STEP 6 Install the dependencies by typing pip install -r requirements.txt.

STEP 7 To hide the message type python LSBSteg.py -i “your image in which you want to hide your messge” -o “output of the image file with the format” -f  ” text file which you want to hide” .



Our image file has prepared.


Extracting the hidden message


Our recipient has receive has received the image file and its time to reveal the hidden message from this image.



STEP 1 To decode the hidden data from the image type decode -i “your image file contain messgae” -o ” output name with file format”



STEP 2 We have extracted the file from the image now its time to read content  from it so type cat msg.txt to read the file.



STEP 3 After downloading the file its time to decrypt it so type gpg -d  “your encrypted file” , it will ask for password enter it and then we will get our secret message.



For more stuff you can follow us on : Facebook



Share with Friends
Use Cybytes and
Tip the Author!
Share with Friends
Ready to share your knowledge and expertise?
  1. Cool! Thanks for sharing.

  2. python3 LSBSteg.py decode -i msg.png -o msg.txt && ls

    Traceback (most recent call last):
    File “LSBSteg.py”, line 17, in
    import cv2
    ModuleNotFoundError: No module named ‘cv2’

    what’s the problem ?

  3. Thank you for this. Very useful

Comment on This

You must be logged in to post a comment.

Our Revolution

We believe Cyber Security training should be free, for everyone, FOREVER. Everyone, everywhere, deserves the OPPORTUNITY to learn, begin and grow a career in this fascinating field. Therefore, Cybrary is a free community where people, companies and training come together to give everyone the ability to collaborate in an open source way that is revolutionizing the cyber security educational experience.

Support Cybrary

Donate Here to Get This Month's Donor Badge


We recommend always using caution when following any link

Are you sure you want to continue?