For the Fêtes de la Science in my university, I had to work a bit on visual cryptography and I thought it could be a nice blog post.
Table of Contents
Disclaimer : In this article we are going to use modulus. If you don’t know what it is, I have written an a small appendix on this at the end.
One Time Pad
In the area of cryptography, there is a scheme that is known to be unconditionnaly secure, but ressource expensive, buceause it requires a key that is as long as the original message. It is called the One Time Pad (OTP).
Let’s have a first example with letters. Let’s suppose we exchange message only composed of the uppercase letters A to Z. Each letter can be mapped uniquely to an integer between 0 and 25 (A is 0, B is 1, …, Z is 25). Now let’s suppose that we want to exchange the message
The OTP requires that we have a key with the same length as the message. I hence generate a random string of length 13 with uppercase letter and I have the following key
To have the encrypted message, we will have to make a sum between the message and the key. In fact for each character, we are going to make the following operations :
- Get the indexes corresponding to the char of the message and the key between 0 and 25;
- Sum the two indexes with modulus 26 (that ensures that the result stays between 0 and 25);
- We now have the index of the encrypted string.
Let’s do it witt the example :
|Message||Key||Index message||Index key||Sum||Sum modulus 26||Encrypted character|
and hence the encrypted message is then
Now we are going to get the decryption process and then see why it’s properly secure.
The decryption process is similar to the encryption process :
- Get the indexes corresponding to the char of the encrypted message and the key between 0 and 25;
- Compute the difference between the index of the encrypted message and the index of the key modulus 26;
- We now have the index of the message.