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:
One-time pad
Let message.png be this 512×512 image using a 1-bit pallet (Lena with Floyd–Steinberg dithering):
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
Considerations
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.
Be First to Comment