Caesar Cipher :A Classical Cryptography technique.

Caesar Cipher :A Classical Cryptography technique.

Cryptography has been a cornerstone of secure communication for centuries, allowing individuals to encode their messages in a way that only the intended recipients can understand. From all the cryptographic techniques, the most easy is the Caesar Cipher. It is named after a Roman general 'Julius Caesar'. It is a type of substitution cipher where each letter in a plain text is shifted a certain number of places up or down the alphabet. Despite its simplicity it laid the groundwork for many complex cryptographic methods.

For encryption and decryption we should convert all characters to equivalent numbers and the easiest way is to use the ASCII value of the alphabet to give them a number.

e.g. ASCII value of 'a' is 97. Hence the mapping is done as follows:

  • a -> ASCII(a) - ASCII(a) -> 97-97 = 0

  • b -> ASCII(b) - ASCII(a) -> 98-97 = 1

  • c -> ASCII(c) - ASCII(a) -> 99-97 = 2

  • d ->ASCII(d) - ASCII(a) -> 100-97 = 3

    ..........

  • z -> ASCII(z) - ASCII(a) -> 122-97 = 25

Similarly ASCII value of 'A' is 65. Hence the mapping is done as follows:

  • A -> ASCII(A) - ASCII(A) -> 65-65 = 0

  • B -> ASCII(B) - ASCII(A) -> 66-65 = 1

  • C -> ASCII(C) - ASCII(A) -> 67-65 = 2

  • D -> ASCII(D) - ASCII(A) -> 68-65 = 3

    ..........

  • Z -> ASCII(Z) - ASCII(A) -> 90-65 = 25

Encryption Process:

Let's say we want to encrypt a message: "Hello Z World!" with a shift of 3. Here we say that key = 3.

For encryption of a letter c we use enc(c) = (NumberMap(c) + 3)%26. Modulo(%) is used to rotate encryption of 'Z' back to 'C' if key = 3.

enc stands for encryption.

1)Shift Letters by key = 3:

  • enc(H) ->(7+3)%26 = 10 -> K

  • enc(e) -> (4+3)%26 = 7 -> h

  • enc(l) -> (11+3)%26 = 14 -> o

  • enc(l) -> (11+3)%26 = 14 -> o

  • enc(o) -> (14+3)%26 = 17 -> r

  • enc(Z) -> (25+3)%26 = 2 -> C

  • enc(W) -> (22+3)%26 = 25 -> Z

  • enc(o) -> (14+3)%26 = 17 -> r

  • enc(r) -> (17+3)%26 = 20 -> u

  • enc(l) -> (11+3)%26 = 14 -> o

  • enc(d) -> (3+3)%26 = 6 -> g

  • ! -> !

2)Resulting Cipher Text:

The message "Hello Z World!" is encrypted to "Khoor C Zruog!".

Decryption Process:

Now we decrypt the message "Khoor C Zruog!" using the same key.

For decryption of a letter c we use dec(c) = (NumberMap(c) - 3)%26. Modulo(%) is used to rotate decryption of 'C' back to 'Z' if key = 3.

1)Shift letters back by key = 3:

  • dec(K) -> (10-3)%26 = 7 -> H

  • dec(h) -> (7-3)%26 = 4 -> e

  • dec(o) -> (14-3)%26 = 11 -> l

  • dec(o) -> (14-3)%26 = 11 -> l

  • dec(r) -> (17-3)%26 = 14 -> o

  • dec(C) -> (2-3)%26 = 25 -> Z

  • dec(Z) -> (25-3)%26 = 22 -> W

  • dec(r) -> (17-3)%26 = 14 -> o

  • dec(u) -> (20-3)%26 = 17 -> r

  • dec(o) -> (14-3)%26 = 11 -> l

  • dec(g) -> (6-3)%26 = 3 -> d

  • ! -> !

2)Resulting Plain Text:

The cipher text "Khoor C Zruog!" is decrypted back to "Hello World!".

Let's implement the code in python!

1)Code for encryption:

ord() gives ASCII value of character and chr() gives character to a corresponding ASCII value.

Output:

  1. Code for decryption:

Output:

Advantage:

  • It is the simplest cryptographic technique making it easy to understand and implement.

Disadvantage:

  • It is extremely vulnerable to brute force attacks since there are 25 possible shifts.

  • Since it is a simple substitution cipher, hence the patterns in the plain text are preserved in the cipher text making it susceptible to frequency analysis.

Applications:

Caesar Cipher is no longer used for serious encryption but its principles help illustrate fundamental concepts such as substitution and key-based encryption, which are foundational to understanding more advanced methods like the Vigenère cipher and modern-day algorithms like AES.

Conclusion:

By understanding the Caesar Cipher, we gain insights into the evolution of cryptography and the basic principles that underlie more complex encryption methods.