LSB Image Steganography Using Python

Overview

Understanding-Steganography-With-Python

LSB Image Steganography Using Python

📗 Description:

💣 WHAT IS STEGANOGRAPHY?

Steganography is the science that involves communicating secret data in an appropriate multimedia carrier, e.g., image, audio, and video files. It comes under the assumption that if the feature is visible, the point of attack is evident, thus the goal here is always to conceal the very existence of the embedded data.

💣 WHAT IS LSB IMAGE STEGANOGRAPHY?

LSB Steganography is an image steganography technique in which messages are hidden inside an image by replacing each pixel’s least significant bit with the bits of the message to be hidden.

🏹 Encode Part:

1.Step:

Firstly, we write the code to convert the source image into a NumPy array of pixels and store the size of the image. if image mode equal RGB n value will be 3 or if image mode RGBA n value equal 4 or is not equal any mode n value will be zero. Calculate Total pixel of image.

def encode(src, message, dest):

img = Image.open(src, 'r')
width, height = img.size
array = np.array(list(img.getdata()))

if img.mode == 'RGB':
    n = 3
elif img.mode == 'RGBA':
    n = 4
else:
    n =0
total_pixels = array.size//n

2.Step:

Secondly, we add a delimiter (“$t3g0") at the end of the secret message, so that when the program decodes, it knows when to stop.

 message += "$t3g0"
 b_message = ''.join([format(ord(i), "08b") for i in message])
 req_pixels = len(b_message)

3.Step:

Thirdly, we make a check if the total pixels available is sufficient for the secret message or not.

 if req_pixels > total_pixels:
print("ERROR: Need larger file size")

else:
   index=0
   for p in range(total_pixels):
      for q in range(0, 3):
          if index < req_pixels:
              array[p][q] = int(bin(array[p][q])[2:9] + b_message[index], 2)
              index += 1

4.Step:

Finally, we have the updated pixels array and we can use this to create and save it as the destination output image.

                    array=array.reshape(height, width, n)
                    enc_img = Image.fromarray(array.astype('uint8'), img.mode)
                    enc_img.save(dest)
                    print("Image Encoded Successfully")

🏹 Decode Part:

1.Step: Firstly, we repeat a similar procedure of saving the pixels of the source image as an array, figuring out the mode, and calculating the total pixels.

def Decode(src):

img = Image.open(src, 'r')
array = np.array(list(img.getdata()))

if img.mode == 'RGB':
    n = 3
elif img.mode == 'RGBA':
    n = 4

total_pixels = array.size//n

2.Step:

Secondly, we need to extract the least significant bits from each of the pixels starting from the top-left of the image and store it in groups of 8.

               hidden_bits = ""
              for p in range(total_pixels):
                    for q in range(0, 3):
                        hidden_bits += (bin(array[p][q])[2:][-1])

               hidden_bits = [hidden_bits[i:i+8] for i in range(0, len(hidden_bits), 8)]

                message = ""
                for i in range(len(hidden_bits)):
                      if message[-5:] == "$t3g0":
                          break
                       else:
                          message += chr(int(hidden_bits[i], 2))

Last Step:

Finally, we do a check if the delimiter was found or not. If not, that means there was no hidden message in the image.

🥇 Congrats!! Let's call the function:

            encode("TARGET_IMAGE_PATH","YOUR_MESSAGE","DESTINATION_IMAGE_PATH")
            decode("DESTINATION_IMAGE_PATH")
Owner
Mahmut Can Gönül
Software Engineer
Mahmut Can Gönül
Convert a DOS Punk image to text

DOS Punk Text Inspired by MAX CAPACITY's DOS Punks & the amazing DOS Punk community. DOS Punk Text is a Python 3 script that renders a DOS Punk image

4 Jan 13, 2022
Script that organizes the Google Takeout archive into one big chronological folder

Script that organizes the Google Takeout archive into one big chronological folder

Mateusz Soszyński 1.6k Jan 09, 2023
Javascript image annotation tool based on image segmentation.

JS Segment Annotator Javascript image annotation tool based on image segmentation. Label image regions with mouse. Written in vanilla Javascript, with

Kota Yamaguchi 513 Nov 15, 2022
MyPaint is a simple drawing and painting program that works well with Wacom-style graphics tablets.

MyPaint A fast and dead-simple painting app for artists Features Infinite canvas Extremely configurable brushes Distraction-free fullscreen mode Exten

MyPaint 2.3k Jan 01, 2023
Simple Python image processing & automatization project for a simple web based game

What is this? Simple Python image processing & automatization project for a simple web based game Made using only Github Copilot (except the color and

SGeri 2 Aug 15, 2022
An application that maps an image of a LaTeX math equation to LaTeX code.

Convert images of LaTex math equations into LaTex code.

1.3k Jan 06, 2023
Convert photos to paintings with python

Convert-photos-to-paintings Before the changes After the changes Before the changes After the changes This code is written in the Python programming l

Amir Hussein Sharifnezhad 3 May 31, 2022
Simple to use image handler for python sqlite3.

SQLite Image Handler Simple to use image handler for python sqlite3. Functions Function Name Parameters Returns init databasePath : str tableName : st

Mustafa Ozan Çetin 7 Sep 16, 2022
Nutrify - take a photo of food and learn about it

Nutrify - take a photo of food and learn about it Work in progress. To make this a thing, we're going to need lots of food images... Start uploading y

Daniel Bourke 93 Dec 30, 2022
A simple python script to reveal the contents of a proof of vaccination QR code.

vaxidecoder A simple python script to reveal the contents of a proof of vaccination QR code. It takes a QR code image as input, and returns JSon data.

Hafidh 2 Feb 28, 2022
Image manipulation package used for EpicBot.

Image manipulation package used for EpicBot.

Nirlep_5252_ 7 May 26, 2022
This will help to read QR codes using Raspberry Pi and Pi Camera

Raspberry-Pi-Generate-and-Read-QR-code This will help to read QR codes using Raspberry Pi and Pi Camera Install the required libraries first in your T

Raspberry_Pi Pakistan 2 Nov 06, 2021
Tool to create a Phunk image with a custom background

Create Phunk image Tool to create a Phunk image with a custom background Installation Clone the repo git clone https://github.com/albanow/etherscan_sa

Albano Pena Torres 6 Mar 31, 2022
Simple Python / ImageMagick script to package images into WAD3s for use as GoldSrc textures.

WADs Out For [The] Ladies Simple Python / ImageMagick script to package images into WAD3s for use as GoldSrc textures. Development mostly focused on L

5 Apr 09, 2022
HTML2Image is a lightweight Python package that acts as a wrapper around the headless mode of existing web browsers to generate images from URLs and from HTML+CSS strings or files.

A package acting as a wrapper around the headless mode of existing web browsers to generate images from URLs and from HTML+CSS strings or files.

176 Jan 01, 2023
Create QR Code for link using Python

Quick Response QR is short and named for a quick read from a cell phone. Used to view information from transitory media and put it on your cell phone.

Coding Taggers 1 Jan 09, 2022
BeeRef — A Simple Reference Image Viewer

BeeRef — A Simple Reference Image Viewer BeeRef lets you quickly arrange your reference images and view them while you create. Its minimal interface i

Rebecca 245 Dec 25, 2022
A ray tracing render implemented using Taichi language.

A ray tracing render implemented using Taichi language.

Mingrui Zhang 45 Oct 23, 2022
Next-generation of the non-destructive, node-based 2D image graphics editor

Non-destructive, node-based 2D image graphics editor written in Python, focused on simplicity, speed, elegance, and usability

Gimel Studio 238 Dec 30, 2022
Python scripts for semi-automated morphometric analysis of atolls from Landsat satellite Imagery.

AtollGeoMorph Python scripts for semi-automated morphometric analysis of atolls from Landsat satellite Imagery. The python scripts included allow user

1 Dec 16, 2022