Wolfram Language

Open live version

Hide Secret Messages in Images

Hide messages or other data in an image for covert distribution.


code

X
X

how it works

Steganography is a technique for hiding information in images. The hidden information is so subtle that for all practical purposes, it leaves the appearance of the image unchanged.

Convert the carrier image data into bytes and set the least significant bit of each to zero.

In[1]:=
X
In[2]:=
X

Convert the secret message into a list of bits corresponding to the ASCII serialization of the symbolic object representing the message.

In[3]:=
X
In[4]:=
X

Encode the length of the secret message into 48 bits and join this to the message. Then reshape the bit stream to match the shape of the image data. One bit per color channel per pixel.

In[5]:=
X

Add the secret data to the carrier data and turn it back into an image. The image will look the same, but contain the secret message, and can be shared, in plain sight, with your recipient.

In[6]:=
X
Out[6]=

To decode the message, start by extracting the image data and discarding all but the least significant bit of each value.

In[7]:=
X

The first 48 bits tell us how much secret data was encoded.

In[8]:=
X
Out[8]=

Excluding those 48 bits, turn the bit stream into 8-bit blocks.

In[9]:=
X

For each block of bits, up to the end of the message, turn into a byte, then into an ASCII character. Finally de-serialize the character stream to a Wolfram Language expression representing the message payload.

In[10]:=
X
Out[10]=

Those steps are packaged in the functions InsertSecretMessage and ExtractSecretMessage.

In[11]:=
X
In[12]:=
X

You can hide entire functioning applications in images, like this interactive Manipulate of a function plot.

In[13]:=
X