StegoPy - LSB Steganography Tool in Python

Foreword


Recently, I noticed that people on my forum have become interested in the topic of steganography of various texts in images, mp3 files and videos. And then I had the idea to write my own script for steganography of text in images. I have to say right before that I have never encountered writing similar tools for steganography.

Before getting acquainted with LSB-steganography, I considered other ways, or rather, came up with my own. But I didn’t have the strength to come up with something of my own and I decided to google it:

LSB is a steganography method in which the lower bits of one of the RGB colors in a pixel are changed to bits of encoded text.

Then I got acquainted with the Pillow library for working with images and Cryptography. The second in my case was needed to create DES encryption, which will subsequently be bit-coded into the image.

Coding


I posted my brainchild on GitHub, so for further work with StegoPy we just need to clone the project with GitHub:

> git clone https://github.com/eBind/StegoPy
> cd StegoPy
> pip3 install -r requirements.txt
> python3 stegopy.py

Installation

However, everything is as usual in terms of installation. Now let's look at the syntax of the launch commands.

> python3 stegopy.py -e in.jpg data.txt

With this command, we will encode the text from the data.txt file into an in.jpg image .
But before encoding, we will be asked for a balance, which can be from 1 to 4. This is just one of the most interesting things in the program.

File in.jpg


File data.txt
this is private message

Balance is the number of low-order bits involved in steganography. It ranges from 1 to 4.

Accordingly, the greater the balance, the:

  1. Fewer pixels will be involved in coding
  2. Noticeable changes in color channels

From this we can conclude that the smaller the balance, the higher the reliability of steganography and it will be invisible to the human eye.

Another important factor is that only the blue channel changes, the shades of which are the least noticeable to our eyes.

After we have decided on the balance, our script will create two additional files:

  • out.png - image with encoded text
  • key.dat - file with the key that is needed for decryption

File out.png


Key.dat file
1$960$gxvZH4Q8Gq2qLGeA1aSCXIPRljJlJbihsvSBdzx-wSM=

Coding

Decoding


The syntax for the command in our case is:

> python3 ./stegopy.py -d out.png

Then we will be asked the key that we received when coding. After decoding, the decrypted text will be saved in the out.txt file .

Decoding

As you may have noticed, the input image is in JPEG format, and the output is PNG. This is a flaw in the program, which will soon be fixed and you will have the opportunity to choose the output format.

Only JPEG and PNG were tested on the input image, theoretically it should work on less used ones, such as bmp and so on.

By the way, pylint rated StegoPy at 10/10. Comments on the code and functionality are welcome as I plan to develop the application.

The project is available on GitHub

All Articles