Hide Secret Message Inside an Image Using LSB-Steganography

Profile image for shaquib
March 7, 2018 | Views: 1918

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. Profile image for jmcedric

    Thank you for this. Very useful

Comment on This

You must be logged in to post a comment.

Get more out of Cybrary
Reach an audience of 1,500,000+ IT and cyber professionals, including the world's top companies
Create impact at a scale by reaching a global audience
Build your personal brand
Supplement or replace your income (average instructor makes ~$1,000 - $2,000/month)
Access the world's largest talent pool of cyber security professionals, and receive candidates with pre-assessed technical skills
Eliminate the pain and costs of technical vetting
Receive candidate skill profiles highlighting knowledge and technical proficiency
Reach active and passive candidates; and, fill your pipeline with pre-vetted, qualified cyber professionals
Get a Job
Work with a dedicated mentor to help you select the career that's right for you, and get a job at one of the world's top companies.
Receive all the training and assessments you need to prepare for the job
Work with a dedicated Mentor
Get placed through Cybrary for jobs earning average salaries of $116,000/yr

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.

Cybrary On The Go

Get the Cybrary app for Android for online and offline viewing of our lessons.

Get it on Google Play

Support Cybrary

Donate Here to Get This Month's Donor Badge

Skip to toolbar

We recommend always using caution when following any link

Are you sure you want to continue?