Brute Force Caesar Cipher (Python)

Brute Force Caesar Cipher

“The Caesar Cipher (Caesar Shift, Caesar’s Code) is a simple, easy to implement substitution cipher. The cipher is named after Julius Caesar. The cipher works by taking the letters of the message and then shifts the letter a defined space along the alphabet.

For example a shift of 1 character would make a=b, b=c, c=d etc.”

I have looked at creating a few ways to use the Caesar Cipher, however I’ve never included a brute force method which is something I am going to correct now.

Brute Force Caesar Cipher

letters = “abcdefghijklmnopqrstuvwxyz”
enc_string = “hpwwozypjzfnclnvpoespnzopjzflcpyzhlyzqqtntlwnzopmcplvpcszhhzfwojzftx aczgpespnlpdlcntaspcezxlvpteslcopcezmcplvcplozyezespypiedepaezqtyozfe”
x = 0
while x < 26:
x = x + 1
for character in stringtodecrypt:
position = letters.find(character)
newposition = position-ciphershift
if character in letters:
stringdecrypted = stringdecrypted + letters[newposition]
stringdecrypted = stringdecrypted + character
print(“You used a cipher shift of “+ciphershift)
print(“Your decrypted message reads:”)


The Python program takes an encrypted string and then outputs all possibilities of the string by cycling through each possible Caesar Cipher. For small strings this is quite quick, however for larger strings it will take longer. Possible future improvements would be outputting all possibilities to different text files, and/or using character frequency to pick out the possible vowels.

This blog post was inspired by the Future Learn course, “Introduction to Encryption and Cryptography” which I am currently undertaking. The GitHub for my Caesar Cipher Python files is available at:

My previous posts on the Caesar Cipher can be found at:


Python (with a graphical user interface):


3 thoughts on “Brute Force Caesar Cipher (Python)

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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