Skip to content

Tag: Gimp

One-time pad using GIMP

With a ∈ {0,1} and b ∈ {0,1}, the XOR function {0,1}→{0,1} can be defined by the truth table:

a b a XOR b
0 0 0
0 1 1
1 0 1
1 1 0

Gimp doesn’t have a layer operation called XOR but there is the “Difference” mode defined by the Gimp User Manual by the equation:

$latex E =|I – M|$

Applying the formula to the Red Green Blue color mode for a pixel we have:

$latex rgb(|r_I-r_M|,|g_I-g_M|,|b_I-b_M|) =|rgb(r_I,g_I,b_I) – rgb(r_M,g_M,b_M)|$

The truth table for the “difference” mode is:

I M |I – M|
rgb(0,0,0) rgb(0,0,0) rgb(0,0,0)
rgb(0,0,0) rgb(255,255,255) rgb(255,255,255)
rgb(255,255,255) rgb(0,0,0) rgb(255,255,255)
rgb(255,255,255) rgb(255,255,255) rgb(0,0,0)

Let’s call black-white representation this binary pallet:

  • the white color, i.e. rgb(255,255,255), represent the number 1
  • the black color, i.e. rgb(0,0,0), represent the number 0.

Then the truth table for the difference is the same as the XOR one.

Experimenting with images

Let A_0101.png be this image:

And B_0011.png be this image:

Notice that each image use the black-white representation of the binary message in the file name.

After we apply the “Difference” layer mode with the two images we have what we can call AXORB_0110.png:

A XOR B 0110

One-time pad

Let message.png be this 512×512 image using a 1-bit pallet (Lena with Floyd–Steinberg dithering):

Lena Soderberg

And key.png a image of the same size and pallet with random content:

We can create a image messageXORkey.png using the Gimp’s different mode:


The messageXORkey.png looks as random as the key or any other random key.

Someone in possession of messageXORkey.png and key.png can apply a XOR to retrieve message.png. That’s because:

messageXORkey.png = message.png XOR key.png
messageXORkey.png XOR key.png = message.png XOR key.png XOR key.png
messageXORkey.png XOR key.png = message.png XOR 0
messageXORkey.png XOR key.png = message.png


This was a demonstration of how to use GIMP to encode and decode one-time pads. There are several constraints to use one-time pads in a secure way for practical purposes that you should know before using it in a real situation.

Gimp Small Miracles

Some times a good picture is ruined by a little detail or someone that shouldn’t be there. If you are willing to trade a complete portraying of the reality for a better photo, here are some tips for Gimp. Use them wisely.

Here is the original photo of two friends playing a game, and an unwanted stranger raising his arms right in the middle of the picture.

Here is the most useful tools from the Gimp tool box and how to use them:

Clone tool. The most common tool to create remove unwanted things. Usually you use them by getting a background theme and cloning it to cover what you want to hide. The best way to use this tool is when you have a not uniform background, like a wall or grass, where a small pattern repeats.

Free Selection (Lasso). When the clone tool is not enough because patterns are too big or too shapeless, the best is use the lasso tool. Get a good piece of the background or another object and them copy and paste over what you want to hide. Maybe what you need to select and copy is not in the same image you are working, you can get information from another picture and use in your main picture. This was what I had to do in this example.

Sometimes you have to change the brightness and contrast to match the pasted selection with the main picture.

Perpective tool. This is a very powerful tool because allows you to use a selection from another image but was taken from another point of view and you need to correct it’s perspective. By doing that you can retrieve a lot of information that your picture don’t have by taking them from another pictures. You can also use to fit a pattern.

Smudge tool. When you are handling uniform colors and straight shapes this is a good tool. You can smudge a pasted selection in the boundaries to it match with the main picture. You can also use it to stretch or squeeze shapes, but they have to be very color uniform to it work well. For more complex shapes you can use the IWarp filter.

So, I guess this is the most important about them. Another time I can do some videos showing how to use them better. In this work you can spot several little mistakes because I was very clumsy and in hurry, but the result is satisfactory.



Next time ask people to get out of the way when taking a picture.