How to communicate secretly with SteganoGAN?

Steganography is the term used to refer to covert communication, which is hiding some kind of information in the main medium of communication. Deep learning is also used in this field to develop powerful and secure applications when communication is supposed to be through images. In this article, we will discuss about steganography and its current use with the latest developments. Later we will discuss the SteganoGAN which is a tool that does steganography on images. Here are the main points to be discussed in this article.

Contents

  1. Understanding Steganography
  2. How is it done?
  3. How does SteganoGAN work?
  4. Implementing SteganoGAN

Let’s talk about steganography first.

Understanding Steganography

Steganography is the practice of concealing a secret message inside or even on top of something public. That something can be anything you want it to be. Many examples of steganography today involve embedding a piece of secret text inside an image. Alternatively, you can hide a secret message or script in a Word or Excel document.

The purpose of steganography is to conceal and deceive. It is a type of covert communication in which messages are concealed using any medium. It is not a type of cryptography as it does not involve the scrambling of data or the use of a key. Instead, it’s a type of data hiding that can be done in imaginative ways.

How is it done?

The data is encrypted or otherwise obfuscated before being injected into data that is part of a certain type of file, such as a JPEG image, audio or video file, using a special algorithm in today’s digital steganography . The hidden message can be inserted into ordinary data files in various ways.

One way is to disguise the data as bits that represent the same color pixels in the line of an image file. By discretely applying the encrypted data to the redundant data, the result is an image file that looks identical to the original image but contains “noise” patterns of normal unencrypted data.

A common application of steganography is the use of a watermark, which is a mark or other identifying data embedded in media files or other content files. Watermarking is a method used by Internet publishers to determine the origin of media assets that have been downloaded without permission.

A common application of steganography is the addition of a watermark – a mark or other identifying data concealed in media files or other content files. Watermarking is a technique commonly used by online publishers to identify the source of media assets discovered to be shared without permission.

How does SteganoGAN work?

Traditional image steganography techniques are only effective up to a relative payload of about 0.4 bits per pixel. They tend to introduce artifacts beyond this limit, which can be easily spotted by automated steganalysis techniques and, in severe circumstances, by the human eye.

STEGANOGAN is a revolutionary end-to-end model for image steganography that takes advantage of current developments in deep learning. It uses dense connections, which have been shown to improve performance by alleviating the leakage gradient problem.

Multiple loss functions are used in an adversarial training framework to simultaneously optimize the encoder, decoder, and critical networks. We find that our method successfully embeds arbitrary data into cover photos derived from a variety of natural landscapes and achieves peak embedding rates of 4.4 bits per pixel.

Steganography, in its most basic form, involves only two operations: encoding and decoding. The encoding procedure generates a steganographic image from a cover image and a binary message. The decoding operation recovers the binary message from the steganographic image.

Implementing SteganoGAN

To use SteganoGAN, we need to install SteganoGAN via pip or via source by cloning the repository, and we also need to use a dataset to train the GAN. The dataset can be used from the repository. There is a shell file in the directory SteganoGAN/research/data/download.sh by running this file we can download the div2K dataset and MS COCO. Either of these datasets is required for training here. I used the div2k dataset. We can only download the div2k dataset by commenting the script from MS COCO in the .sh file and after saving it, run it as follows.

# downloading the dataset
! /content/SteganoGAN/research/data/download.sh

# installing the architecture
! pip install steganogan

Let’s import the dependencies.

from steganogan import SteganoGAN
from steganogan.critics import BasicCritic
from steganogan.decoders import DenseDecoder
from steganogan.encoders import DenseEncoder
from steganogan.loader import DataLoader
 
import numpy as np

The first import is the SteganoGAN wrapper class which creates the architecture, trains the architecture, loads the previously trained model and, last but not least, performs the encoding and decoding operations.

The next two imports are for the encoder and decoder architecture. Basically, there are three models for each, namely Basic, Residual and Dense. And currently, the implementation part supports the basic and dense architecture.

The next import concerns the data loader. This function is used to load the dataset from the directory and additionally you set some parameters like number of images to use, blending etc.

Now after downloading the dataset by the above shell command, we can load it using the Data Loader function. The dataset is uploaded by default in two splits and the validation here we will use those two.

train = DataLoader('div2k/train/', limit=np.inf, shuffle=True, batch_size=4)
validation = DataLoader('div2k/val/', limit=np.inf, shuffle=True, batch_size=4)

Now that’s all, now we can directly use SteganoGAN’s wrapper class to create the architecture as shown below.

#use the wrapper class
steganogan = SteganoGAN(1, DenseEncoder, DenseDecoder, BasicCritic, hidden_size=32, cuda=True, verbose=True)

In the definition above, we have used the BasicCritic function which is a kind of evaluation function that checks whether a given image is shorthand or not.

Now we can start training. To train this model, it is sufficient to simply call the .fit method as we do with normal ML algorithms by providing the training and validation data.

# train
steganogan.fit(train, validation, epochs=5)

After completing the training, we can use the encoder and decoder functions. Here, the encoder function is used to take three arguments, namely the input image, the output image name and path, and the string or text message to be transmitted.

Here is the image we are using.

# encoding
steganogan.encode('/content/artillery.png','output.png','Fire in the hole!')

Similarly, the decode function only takes the generated image and outputs the above encoded message.

# decoding
steganogan.decode('/content/output.png')

To go out: Fire in the hole!

And here is the output image.

The encoded image looks like the original image as we can see above. Out of curiosity, we can check the difference between the two images using OpenCV as follows.

import cv2
from google.colab.patches import cv2_imshow

# load original image
original = cv2.imread('/content/artillery.png', cv2.COLOR_BGR2RGB)

# loaded coded image
coded = cv2.imread('/content/output.png', cv2.COLOR_BGR2RGB)
 
# subtract two
diffrence = cv2.subtract(original, coded)

# get the result
cv2_imshow(diffrence)

Here is the result,

A complete black image means there is absolutely no difference between the images.

Last words

Through this article, we have learned about steganography which is basically a technique by which one can transmit some kind of information separately between parties. For image steganography we saw the python based tool called SteganoGAN which can encode the arbitrary message to the image and retrieve it, and in the whole process we cannot see any change in the image .

The references

Comments are closed.