Caesar Cipher in Cryptography


A Caesar Cipher is one of the most simple and easily cracked encryption methods.

It is a Substitution Cipher that involves replacing each letter of the secret message with a different letter of the alphabet which is a fixed number of positions further in the alphabet.

For example with a shift of 1, A would be replaced by B, B would become C, and so on. The method is apparently named after Julius Caesar, who apparently used it to communicate with his officials.

Thus to cipher a given text we need an integer value, known as shift which indicates the number of position each letter of the text has been moved down.


centered image


Text : ABCDEFGHIJKLMNOPQRSTUVWXYZ
Shift: 23
Cipher: XYZABCDEFGHIJKLMNOPQRSTUVW

Text : ATTACKATONCE
Shift: 4
Cipher: EXXEGOEXSRGI


Algorithm for Caesar Cipher:

Input:

  1. A String of lower case letters, called Text.
  2. An Integer between 0-25 denoting the required shift.

Procedure:




How to decrypt?

We can either write another function decrypt similar to encrypt, that’ll apply the given shift in the opposite direction to decrypt the original text. However we can use the cyclic property of the cipher under modulo , hence we can simply observe

Cipher(n) = De-cipher(26-n)

Hence, we can use the same function to decrypt, instead we’ll modify the shift value such that shift = 26-shift



Caesar Cipher implementation in python

#A python program to illustrate Caesar Cipher Technique

centered image


Caesar Cipher implementation in C language

#C program to illustrate Caesar Cipher Technique

centered image


Caesar Cipher implementation in Javascript

#A Javascript program to illustrate Caesar Cipher Technique

centered image