Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🇺🇸 🇷🇺
Steganography

Steganography is the practice of representing information within another message or physical object, in such a manner that the presence of the information is not evident to human inspection.

This repository presents a simple way to hide a secret image inside another image:

hiding

As you can see, the result (the image on the right) is almost identical to the source image. However, there is a secret image encrypted inside that can be extracted:

unhiding

 How does it work?
The essence of the method is to take N high bits of each pixel in each of the three channels (R, G, B) of the secret image and insert them in place of N low bits of the source image. For example, if N = 2:

how to hide

The color of the source image is almost unchanged because the difference in the low bits is hard to distinguish by eye. To then extract the secret from such an image, it is necessary to shift N low bits to the place of the high bits:

how to exctract

Obviously, the secret image became lower quality after extraction. The more bits are allocated to it, the more quality it will retain, but also the more likely it will be detected by eye in the source image.

Using

  1. Download utils.py file.

  2. Install required libraries:

pip install numpy==1.26.3
pip install pillow==10.2.0
  1. Use it:
from utils import hide, extract

hide(source_img='source.jpg', # path to source image
     secret_img='secret.jpg', # path to image you want to hide
     save_as='result.png',    # path to save the result
     visibility=2)            # number of bits for secret image

extract(image='result.png',      # path to image with secret
        save_as='extracted.jpg', # path to save extracted image
        visibility=2)            # number of bits for secret image

Note that for saving images with hidden secret it is better to use extensions that compress images little or not at all. Otherwise the hidden image will be impossible to extract!
$\color{Green}\large{\bullet}$ Recommended extensions: .png, .bmp, .tiff, .tif.
$\color{Red}\large{\bullet}$ Сategorically not recommended: .jpg, .jpeg, .gif, .webp, .ico.

About

A simple way to hide one image inside another

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages