Image Secrecy and XOR


Note: If you don’t what an XOR gate is, you might consider reading up on it on wikipedia. It’s not necessary to read the article, but it’s recommended.

The source code for this project can be found at: http://pastebin.com/SLKNLacD

In my previous posts on steganography, we’ve dealt with concealing information inside image, but what if we want to be able to send an image without worrying that people might be able to decipher it?

For this, we can use what is known as a one time pad. We can generate random noise and XOR an image with it and no one will be the wiser. However, this is not very fun. We can employ the same technique to generate a mask to convert an image into another image. But how do we XOR two images?

As you might recall from our posts on encoding bits within images, each pixel consists of 24 bits (8 for red, 8 for green, 8 for blue). So to XOR two images, we simply XOR each pixel in the first image with its corresponding pixel in the second image.

Given an image A and another image B, we’re looking for another image x such that A \oplus x = B. How do we calculate this x?

We notice that A \oplus x = B \leftrightarrow (A \oplus x) \oplus A = B \oplus A.

Because the XOR-operation is associative: (A \oplus x) \oplus A = B\oplus A \leftrightarrow (A \oplus A) \oplus x = B\oplus A.

Anything XOR itself is 0, so: (A \oplus A) \oplus x = B\oplus A \leftrightarrow 0 \oplus x = B\oplus A.

And anything XOR 0 is itself: 0 \oplus x = B\oplus A \leftrightarrow x = B \oplus A.

This means we’ve found a formula for the image x! We’ll now present an example of XOR’ing two image together:

xor_example

It’s quite clear that the last image looks like a weird, trippy morph of the two original images (at least when we know the images we XOR together). And it’s also clear that the regions with a lot of contrast (i.e. the transition from the cats tongue to its fur and the grass) look more random than the regions with low contrast (the region where there’s only grass). We will now show the transition from cat to forest:

xor_example_2

Hey, this is pretty neat! We can use this mask to transform the cat into the forest. What about the other way?

xor_example_3

Yes, we can. This is really cool. We now have an image that we can use to convert the image of the forest to the image of the cat. But is this still steganography? If the image C = A \oplus B was child pornography (or some other illegal image), could you get arrested for possession of A and B? You probably would, as it’s pretty easy to see if you’ve gotten the right image, but presumably, you could XOR any image into any image, as we’ve already shown. Let’s assume that the image of the cat is an illegal one. Under possession of the XOR’ed cat and forest, and the forest, one could claim you were already in possession of the cat. But what stops you from stating that this is what you intended?

xor_example_4

The image to the right would be the one you had originally intended to hide, and the image of the river would then be the key.

Worth a thought.

Advertisements

Comment on this article

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s