1.1.1 Working Of Caesar Cipher

The best way to understand Caesar cipher is to write down the letters from A to Z and assign an index, from 0 to 25, to these letters, as follows In other words, 'A' corresponds to index 0, 'B' corresponds to index 1, and so on. A group of all the letters from A to Z is called the character set:

Now, let's say you want to shift the letters by three positions, then 3 becomes your key. To encrypt the letter 'A', add the index of letter A, which is 0, to the key 3; this results in 0+3 = 3. Now use the result 3 as an index to find the corresponding letter, which is 'D', so 'A' is encrypted to 'D'. To encrypt 'B', you will add the index of 'B' (1) to the key 3, which results in 4, and the index 4 is associated with 'E', so 'B' encrypts to 'E', and so on.

The problem with the previous technique arises when we reach 'X', which has an index of 23. When we add 23+3, we get 26, but we know that there is no character associated with index 26 because the maximum index value is 25. We also know that index 26, should wrap back to index 0 (which is associated with 'A'). To solve this problem, we use the modulus operation with the length of the character set. In this case, the length of the character set ABCDEFGHIJKLMNOPQRSTUVWXYZ is 26. Now, to encrypt 'X', we use the index of 'X' (23) and add it to the key (3) and perform the modulus operation with the length of the character set (26), as follows. The result of this operation is 0, which is used as the index to find the corresponding character, that is, 'A':

(23+3)%26 = 0

The modulus operation allows you to cycle back around to the beginning. You can use the same logic to encrypt all the characters (from A to Z) in the character set and wrap back to the beginning. In Caesar cipher, you can get the index of the encrypted (ciphertext) character using:

(i + key) % (length of the character set)

where i = index of plaintext character

In the same manner, you can get the index of the plaintext (decrypted) character using:

(j - key) % (length of the character set)

where j = index of ciphertext character

The following diagram shows the character set, the encryption, and the decryption of the text "ZEUS" using 3 as the key (shifting three positions). After encryption, the text "ZEUS" is translated to "CHXV", and then the decryption translates it back to "ZEUS".

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.218.127.141