The Vernam cipher, perfect cipher, One-time pad cipher or OTP is a cipher belonging to the group of polyalphabetic ciphers. It is considered to be the only proven cryptographic method that enables unconditionally secure encryption, which has been mathematically proven. It was invented in 1882 and proposed in 1917 by Gilbert Vernam of AT&T.
It resembles a Caesar cipher, but does not move letters the same number of places, but each by a random number and direction.
The Vernam cipher is available in binary and character versions. In the binary version we encrypt / decrypt using the Xor algorithm. However, in the character version we encrypt / decrypt using the Vigenere cipher.
In order for a cipher to be a perfect cipher, the encoding key should meet three conditions:
- must be a random string;
- must be one-time;
- the length of the key must be at least as long as the length of the ciphertext.
For the example of using the Vernam cipher, suppose Eve wants to send a secret message CALCOOLATOR to Adam. Before that, both had received cards with identical keys. Eve chooses an appropriate piece of paper with a key. How to select this card is usually arranged in advance, for example " use the 5th card on March 3rd " or " use the next available card for the next message ".
Each letter in the key will be linked in a specific way to one letter of the message. Often, but not required, each letter is assigned a numerical value (in alphabetical order) e.g. 'A' is 0, 'B' is 1, 'C' is 2 etc.
The coding technique involves combining a key and a message using modular addition. The numerical values of the corresponding messages and letters are added together, modulo 26 (for the Latin alphabet).
Suppose the secret key is MWZYOWBXNIW then the encoding of the word CALCOOLATOR will be done as follows:
C A L C O O L A T O R message
2(C) 0(A) 11(L) 2(C) 14(O) 14(O) 11(L) 0(A) 19(T) 14(O) 17(R) number letter
+ 12(M) 22(W) 25(Z) 24(Y) 14(O) 22(W) 1(B) 23(X) 13(N) 8(I) 22(W) key
= 14 22 36 26 28 36 12 23 32 22 39 message+key
= 14(O) 22(W) 10(K) 0(A) 2(C) 10(K) 12(M) 23(X) 6(G) 22(W) 13(N)(message+key) mod 26
O W K A C K M X G W N cipher
We numbered the letters from 0 to 25 (26 letters in the Latin alphabet from A to Z). If during the encryption, as a result of adding, we get a number greater than 25, then "we turn the counter" from zero, i.e. 26-> 0 that is A, 27-> 1 that is B, 28-> 2 that is C etc.
As a result of encoding the word CALCOOLATOR with the key MWZYOWBXNIW Eve would receive the code OWKACKMXGWN .
To decode the ciphertext, Adam has to do the same thing as Eve, except that instead of adding he has to subtract values.
O W K A C K M X G W N cryptogram
14(O) 22(W) 10(K) 0(A) 2(C) 10(K) 12(M) 23(X) 6(G) 22(W) 13(N) cipher
- 12(M) 22(W) 25(Z) 24(Y) 14(O) 22(W) 1(B) 23(X) 13(N) 8(I) 22(W) key
= 2 0 -15 -24 -12 -12 11 0 -7 14 -9 key-cipher
2(C) 0(A) 11(L) 2(C) 14(O) 14(O) 11(L) 0(A) 19(T) 14(O) 17(R) message
C A L C O O L A T O R message
If the result of the subtraction is negative, then the result is subtracted from the number 26, e.g. the result is -7 so 26-7 = 19 that is the letter T.
More on: Wikipedia - One-time pad