Skip to main content

Caesar Cipher

Definition​

The Caesar Cipher is a simple substitution cipher technique in cryptography. It involves shifting the letters of the alphabet by a fixed number of positions. It's named after Julius Caesar, who is reputed to have used it to communicate with his generals

Practice​

caesarCipher(plaintext, shift):
ciphertext = ""
for each character in plaintext:
if character is an uppercase letter:
shifted_char = (character + shift - 'A') % 26 + 'A'
else if character is a lowercase letter:
shifted_char = (character + shift - 'a') % 26 + 'a'
else:
shifted_char = character
ciphertext += shifted_char
return ciphertext