Caesar Cipher
Caesar Cipher was named after Julius Caesar |
You might be wondering with 9 as a shift key, how A would become J and K would become T? Well, the answer to this question is really very simple. We first encrypted A and it became J because the shift key was 9. Shift key is used to determine the position of alphabet with which our plain text will be replaced with. Taking A=0, B=1 ... Z=26, the position of J will be 9 i.e. J=9 so A will be replaced with the alphabet which is at 9th position.
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
Example
Now, we will be using the shift key as 14 to encrypt all 26 alphabets of English language.
Plain text : ABCDEFGHIJKLMNOPQRSTUVWXYZ
Encrypted (shift key 14) : OPQRSTUVWXYZABCDEFGHIJKLMN
While encryption, the plain text alphabet is replaced with the corresponding alphabet depending upon the shift key used, decryption is done in reverse. In the below example we will be decrypting a small message which is encrypted using the shift key 2
Cipher text : ygneqog vq vjg dnqi
Plain text : welcome to the blog
Encryption of a letter x by a shift n can also be described as:
En(x)=(x+n) mod 26
Similarly the decryption would be:
Dn(x)=(x-n) mod 26
PHP code for encryption:
Similarly for decryption we have:Caesar cipher is very easy to crack manually also, just use your brain a bit ;) So at last I have got a small message for you to decrypt, I encrypted the message with the shift key 17
pfl tirtbvu ! jyriv kyv gfjk reu yvcg lj kf xifn