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")
You might also like...
An open source image editor which can manipulate an image in many ways!

Image Editor - An open source image editor which can manipulate an image in many ways! If you need any more modes in repo or I

Image enhancing model for making a blurred image to be somehow clearer than before

This is a very small prject which helps in enhancing the images by taking a Input images. This project has many features like detcting the faces and enhaning the faces itself and also a feature which enhances the whole image

Easily turn large sets of image urls to an image dataset. Can download, resize and package 100M urls in 20h on one machine.
Easily turn large sets of image urls to an image dataset. Can download, resize and package 100M urls in 20h on one machine.

img2dataset Easily turn large sets of image urls to an image dataset. Can download, resize and package 100M urls in 20h on one machine. Also supports

This app finds duplicate to near duplicate images by generating a hash value for each image stored with a specialized data structure called VP-Tree which makes searching an image on a dataset of 100Ks almost instantanious
This app finds duplicate to near duplicate images by generating a hash value for each image stored with a specialized data structure called VP-Tree which makes searching an image on a dataset of 100Ks almost instantanious

Offline Reverse Image Search Overview This app finds duplicate to near duplicate images by generating a hash value for each image stored with a specia

Quickly 'anonymize' all people in an image. This script will put a black bar over all eye-pairs in an image

Face-Detacher Quickly 'anonymize' all people in an image. This script will put a black bar over all eye-pairs in an image This is a small python scrip

Fast Image Retrieval is an open source image retrieval framework

Fast Image Retrieval is an open source image retrieval framework release by Center of Image and Signal Processing Lab (CISiP Lab), Universiti Malaya. This framework implements most of the major binary hashing methods, together with both popular backbone networks and public datasets.

Fast Image Retrieval (FIRe) is an open source image retrieval project

Fast Image Retrieval (FIRe) is an open source image retrieval project release by Center of Image and Signal Processing Lab (CISiP Lab), Universiti Malaya. This project implements most of the major binary hashing methods to date, together with different popular backbone networks and public datasets.

This piece of code is a User Welcomer with Image Manipulation using Python and Pillow (PIL).

This piece of code is a User Welcomer with Image Manipulation using Python and Pillow (PIL).

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

Owner
Mahmut Can Gönül
Software Engineer
Mahmut Can Gönül
Steganography Image/Data Injector.

Byte Steganography Image/Data Injector. For artists or people to inject their own print/data into their images. TODO Add more file formats to support.

Ori 4 Nov 16, 2022
Anaglyph 3D Converter - A python script that adds a 3D anaglyph style effect to an image using the Pillow image processing package.

Anaglyph 3D Converter - A python script that adds a 3D anaglyph style effect to an image using the Pillow image processing package.

Kizdude 2 Jan 22, 2022
Simple Python package to convert an image into a quantized image using a customizable palette

Simple Python package to convert an image into a quantized image using a customizable palette. Resulting image can be displayed by ePaper displays such as Waveshare displays.

Luis Obis 3 Apr 13, 2022
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

null 1 Mar 2, 2022
A pure python implementation of the GIMP XCF image format. Use this to interact with GIMP image formats

Pure Python implementation of the GIMP image formats (.xcf projects as well as brushes, patterns, etc)

FHPyhtonUtils 8 Dec 30, 2022
Image-Viewer is a Windows image viewer based on Python 3.

Image-Viewer Hi! Image-Viewer is a Windows image viewer based on Python 3. Using You must download Image-Viewer.exe from the root of the repository. T

null 2 Apr 18, 2022
Image Reading, Metadata Conversion, and Image Writing for Microscopy Images in Python

AICSImageIO Image Reading, Metadata Conversion, and Image Writing for Microscopy Images in Pure Python Features Supports reading metadata and imaging

Allen Institute for Cell Science - Modeling 137 Dec 14, 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

null 48 Jan 5, 2023
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
Pyconvert is a python script that you can use to convert image files to another image format! (eg. PNG to ICO)

Pyconvert is a python script that you can use to convert image files to another image format! (eg. PNG to ICO)

null 1 Jan 16, 2022