Caesar Cipher

TheĀ Caesar Cipher is one of the most commonly used and simplest ciphers, named afterĀ Julius Caesar, it is a great place to start learning about ciphers.

Encryption

The key is an integer normally known as the ‘shift’, it can be a number from 0-25 (0 being the identity). First you create your alphabet mapping of plaintext letters (lowercase) to ciphertext letters (uppercase) using the shift.

Some examples a shifts would look like this

Shift of 1:                Shift of 21:
abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz
BCDEFGHIJKLMNOPQRSTUVWXYZA VWXYZABCDEFGHIJKLMNOPQRSTU

For each letter in your plaintext you replace it it with its corresponding ciphertext letter (the one below it in the mapping).

It can also be thought of like converting each letter to is equivalent value (A=0, B=1…. Z=25 etc) and adding the key shift, and subtracting 26 if the value is 26 or greater,Ā then convert back to letters.

Example:

Encrypting “when the clock strikes twelve attack” using the shift of 21

when the clock strikes twelve attack
RCZI OCZ XGJXF NOMDFZN ORZGQZ VOOVXF

Decryption

For each letter in your ciphertext you replace it it with its corresponding plaintext letter (the one above it in the mapping).

You can also convert each letter to is equivalent value (A=0, B=1…. Z=25 etc) and subtract the key shift this time, and add 26 if the value smaller than 0,Ā then convert back to letters.

VWXYZABCDEFGHIJKLMNOPQRSTU - Shift of 21:
abcdefghijklmnopqrstuvwxyz 

RCZI OCZ XGJXF NOMDFZN ORZGQZ VOOVXF
when the clock strikes twelve attack

As we are working in modular 26 a shift of -5 is the same as a shift of 21. The inverse key of 21 would be 5.

New: Try it yourself!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.