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
Automatic picture transmission(APT) protocol decoder for NOAA weather satellites

Automatic picture transmission(APT) decoder Automatic picture transmission protocol is used by NOAA satellites. They constantly send a frequency modul

Jayachandra Kasarla 25 Aug 05, 2022
Maze generator with most popular shapes - hexagon, triangle, square

Maze-Generator Maze generator with most popular shapes - hexagon, triangle, square (sqaure not implemented yet): Theory: Planar Graph https://en.wikip

Kacper Plesiak 2 Dec 28, 2021
A tool and a library for SVG path data transformations.

SVG path data transformation toolkit A tool and a library for SVG path data transformations. Currently it supports a translation and a scaling. Usage

Igor Mikushkin 2 Mar 07, 2022
Semi-hash-based Image Generator

pixel-planet Semi-hash-based Image Generator Utilizable for NFTs Generation Process Input is salted and hashed Colors (background, planet, stars) are

Bill Ni 3 Sep 01, 2022
An async Python library to automate solving ReCAPTCHA v2 by audio using Playwright.

Playwright nonoCAPTCHA An async Python library to automate solving ReCAPTCHA v2 by audio using Playwright. Disclaimer This project is for educational

Michael Mooney 69 Dec 28, 2022
FrostedGlass is a translucent frosted glass effect widget, that creates a context with the background behind it.

FrostedGlass FrostedGlass is a translucent frosted glass effect widget, that creates a context with the background behind it. The effect is drawn on t

Kivy Garden 24 Dec 10, 2022
An esoteric visual language that takes image files as input based on a multi-tape turing machine, designed for compatibility with C.

vizh An esoteric visual language that takes image files as input based on a multi-tape turing machine, designed for compatibility with C. Overview Her

Sy Brand 228 Dec 17, 2022
image-processing exercises.

image_processing Assignment 21 Checkered Board Create a chess table using numpy and opencv. view: Color Correction Reverse black and white colors with

Benyamin Zojaji 25 Dec 15, 2022
QR Code Generator

In this project, we'll be using some libraries to instantly generate authentic QR Codes and export them in various formats

Hassan Shahzad 3 Jun 02, 2022
QR Generator using GUI with Tinker

BinCat Token System Very simple python script with GUI that generates QR codes. It don't include a QR "decription" tool. It only generate-it and thats

Hipotesi 1 Nov 06, 2021
PSD (Photoshop, Krita, Gimp...) -> Godot.

limage v0.2.2 Features Getting Started Tags Settings Todo Customizer Changes Solutions WARNING: Requires Python to be installed PSD (Photoshop, Krita,

21 Nov 10, 2022
Raven is a tool written in Python3 allowing you to generate an unique image with some text.

🐦 Raven is a tool written in Python3 allowing you to generate an unique image with some text. It does it by searching the text on Google, do

Billy 39 Dec 20, 2022
A Python Script to convert Normal PNG Image to Apple iDOT PNG Image.

idot-png-encoder A Python Script to convert Normal PNG Image to Apple iDOT PNG Image (Multi-threaded Decoding PNG). Usage idotpngencoder.py -i inputf

Lrdcq 2 Feb 17, 2022
Make GIFs from time-stacked xarray.DataArrays (time, [optional band], y, x), dead-simple.

GeoGIF Make GIFs from time-stacked xarray.DataArrays (time, [optional band], y, x), dead-simple. from geogif import gif, dgif gif(data_array) dgif(das

Gabe Joseph 47 Dec 22, 2022
Python-fu-cartoonify - GIMP plug-in to turn a photo into a cartoon.

python-fu-cartoonify GIMP plug-in to turn a photo into a cartoon. Preview Installation Copy python-fu-cartoonify.py into the plug-in folder listed und

Pascal Reitermann 6 Aug 05, 2022
3D printer / slicing GUI built on top of the Uranium framework

Cura Ultimaker Cura is a state-of-the-art slicer application to prepare your 3D models for printing with a 3D printer. With hundreds of settings and h

Ultimaker 4.4k Jan 02, 2023
An ascii art generator that's actually good. Does edge detection and selects the most appropriate characters.

Ascii Artist An ascii art generator that's actually good. Does edge detection and selects the most appropriate characters. Installing Installing with

18 Jan 03, 2023
A Icon Maker GUI Made - Convert your image into icon ( .ico format ).

Icon-Maker-GUI A Icon Maker GUI Made Using Python 3.9.0 . It will take any image and convert it to ICO file, for web site favicon or Windows applicati

Insanecodes 12 Dec 15, 2021
Nanosensor Image Processor (NanoImgPro), a python-based image analysis tool for dopamine nanosensors

NanoImgPro Nanosensor Image Processor (NanoImgPro), a python-based image analysis tool for dopamine nanosensors NanoImgPro.py contains the main class

1 Mar 02, 2022
Seaborn-image is a Python image visualization library based on matplotlib and provides a high-level API to draw attractive and informative images quickly and effectively.

seaborn-image: image data visualization Description Seaborn-image is a Python image visualization library based on matplotlib and provides a high-leve

48 Jan 05, 2023