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
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 and another image , we’re looking for another image such that . How do we calculate this ?
We notice that .
Because the XOR-operation is associative: .
Anything XOR itself is 0, so: .
And anything XOR 0 is itself: .
This means we’ve found a formula for the image ! We’ll now present an example of XOR’ing two image together:
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:
Hey, this is pretty neat! We can use this mask to transform the cat into the forest. What about the other way?
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 was child pornography (or some other illegal image), could you get arrested for possession of and ? 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?
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.