paint-brush
The Caesar Cipher: One of the Earliest, and Simplest, Encryptionsby@tyler775
129 reads

The Caesar Cipher: One of the Earliest, and Simplest, Encryptions

by Tyler Mc.July 11th, 2023
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

The Caesar cipher is a form of basic encryption and one of the earliest encryption algorithms in humanity’s recorded history. The code was invented by Julius Caesar to protect messages of military significance from prying eyes. Even with basic Python, you can easily turn some text into a basic encrypted cipher using the following function.
featured image - The Caesar Cipher: One of the Earliest, and Simplest, Encryptions
Tyler Mc. HackerNoon profile picture



Cryptography has been around long before modern computers and has been a great way to protect messages. When it comes to providing information while keeping it concealed from those who wish to use it for ill intentions, you need cryptography and codes to encrypt messages to keep them confidential. Back in the days of Rome and Julius Caesar, code was invented - a form of basic encryption and one of the earliest encryption algorithms in humanity’s recorded history - that would allow his messages of military significance to stay safe from prying eyes. This code was named after Julius himself and it was called the Caesar cipher.


According to the Roman historian Suetonius, the cipher was used to shift three letters to create a new code to protect messages. For example, if you want to encrypt the word/letter A, you would shift three letters down the alphabet and translate that ‘A’ into the letter ‘D’ & you decrypt the letter by going three letters back into an A. Suetonius describes the encryption in one of his writings:


"If he had anything confidential to say, he wrote it in cipher, that is, by so changing the order of the letters of the alphabet, that not a word could be made out. If anyone wishes to decipher these, and get at their meaning, he must substitute the fourth letter of the alphabet, namely D, for A, and so with the others." - Suetonius, Life of Julius Caesar 56


One of the great things about the Caesar cipher is how easy this form of encryption is to recreate with modern code. Even with basic Python, you can easily turn some text into a basic encrypted cipher using the following function:


def encrypt(text,s):
    result = ""
 
    
    for i in range(len(text)):
        char = text[i]
 
        # Encrypt the uppercase characters or lowercase letters as determined by an if statement
        # before adding to the result variable
        if (char.isupper()):
            result += chr((ord(char) + s-65) % 26 + 65)
 
        
        else:
            result += chr((ord(char) + s - 97) % 26 + 97)
 
    return result


Unfortunately, the Caesar cipher probably would not work very well in a modern context since it is pretty easily broken since there are only so many different combinations of letter shifting you can use and, eventually, the code can be broken with brute force attacks.


This is something you can also easily program in Python:


def crack(message):

for i in range(len(LETTERS)):
   translated = ''
   for s in message:
      if s in LETTERS:
         num = LETTERS.find(symbol)
         num = num - i
         if num < 0:
            num = num + len(LETTERS)
         translated = translated + LETTERS[num]
      else:
         translated = translated + s

print('Potential Hacked Messages #%s: %s' % (i, translated))


Even Caesar himself worked to combine the Caesar cipher with more complicated systems in order to make more complicated encryptions. That all being said, the Caesar cipher is a pretty important part of the history of cryptography and is one of the earliest recorded encryption algorithms used in a practical context.