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
A Python3 library to generate dynamic SVGs

The Python library for generating dynamic SVGs using Python3

1 Dec 23, 2021
GTK and Python based, simple multiple image editor tool

System Monitoring Center GTK3 and Python3 based, simple multiple image editor tool. Note: Development of this application is not completed yet. The ap

Hakan Dündar 1 Feb 02, 2022
Unique image & metadata generation using weighted layer collections.

nft-generator-py nft-generator-py is a python based NFT generator which programatically generates unique images using weighted layer files. The progra

Jonathan Becker 243 Dec 31, 2022
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
Music Thumbnail Maker

Music Thumbnail Installing pip install TMFrame

krypton 4 Jan 28, 2022
Kainat 13 Mar 07, 2022
Forza painter app with python

forza-painter Discord: A-Dawg#0001 (AE) Supports: Forza Horizon 5 Offically (OTHER v1.405.2.0, MS STORE v3.414.967.0, STEAM v1.414.967.0) Unofficially

320 Dec 31, 2022
A python program to generate ANSI art from images and videos

ANSI Art Generator A python program that creates ASCII art (with true color support if enabled) from images and videos Dependencies The program runs u

Pratyush Kumar 12 Nov 08, 2022
Create a random fluent image based on multiple colors.

FluentGenerator Create a random fluent image based on multiple colors. Navigation Example Install Update Usage In Python console FluentGenerator Fluen

1 Feb 02, 2022
Draw a torus passing through three given points.

PyTorusThreePoints Draw a torus passing through three given points. Usage import numpy as np import pyvista as pv from torus_three_points.main import

2 Nov 19, 2021
A SIXEL encoder/decoder implementation derived from kmiya's sixel

libsixel What is this? This package provides encoder/decoder implementation for DEC SIXEL graphics, and some converter programs. (https://youtu.be/0Sa

Hayaki Saito 2k Jan 09, 2023
The ctypes-based simple ImageMagick binding for Python

Wand Wand is a ctypes-based simple ImageMagick binding for Python, supporting 2.7, 3.3+, and PyPy. All functionalities of MagickWand API are implement

Eric McConville 1.2k Dec 30, 2022
Glyphtracer is an app for converting images of letters to a font

Glyphtracer takes an image that contains pictures of several letters. It recognizes all them and lets the user tag each letter to a Unicode code point. It then converts the images to vector form and

Jussi Pakkanen 38 Dec 24, 2022
Pixel art as well as various sets for hand crafting

Pixel art as well as various sets for hand crafting

1 Nov 09, 2021
Goddard Image Analysis and Navigation Tool

Copyright 2021 United States Government as represented by the Administrator of the National Aeronautics and Space Administration. No copyright is clai

NASA 12 Dec 23, 2022
View images in the terminal using ansi escape codes and python

terminal-photo-viewer view images in the terminal using ansi escape codes and python !! Only tested on Ubuntu 20.04.3 LTS with python version 3.8.10 D

1 Nov 30, 2021
PyLibTiff - a wrapper to the libtiff library to Python using ctypes

PyLibTiff is a package that provides: a wrapper to the libtiff library to Python using ctypes. a pure Python module for reading and writing TIFF and L

Pearu Peterson 105 Dec 21, 2022
ScreenTeX is a tool that grabs all text when taking a screenshot rather than getting an image.

The ScreenTeX project By: Seanpm2001 / ScreenTeX, Et; Al. Top README.md Read this article in a different language 🌐 List of languages Sorted by: A-Z

Sean P. Myrick V19.1.7.2 3 Oct 25, 2022
A simple Streamlit Component to compare images in Streamlit apps. It integrates Knightlab's JuxtaposeJS

streamlit-image-juxtapose A simple Streamlit Component to compare images in Streamlit apps using Knightlab's JuxtaposeJS. The images are saved to the

Robin 30 Dec 31, 2022
Leshycam - Generate Inscryption styled portrait sprites from any image

Leshy's Camera Generate Inscryption styled portrait sprites from any image. Setu

3 Sep 27, 2022