Okay, so we learnt how to implement Caesar cipher in the previous article. We saw the Key space for it was pretty small, i.e., basically the size of list of supported symbols.

So, if you were to brute force it, how many possible keys do you think will be there ? The number of keys is equal to the size or length of the supported symbols list. In our case, the length of string was 95. So, it’ll just take 95 attempts, with all possible keys, and the cipher breaks.

And with today’s computing power, it will take just a few milliseconds to achieve that, even with an old boxed machine.

This very well explains why it’s such a bad idea to use **Caesar Cipher** and why one should never use it.

Now we’ll put together a python script to brute force through the encrypted text.

## Python implementation:

### Step 1:

Declare a function, hack_caesar_cipher(), which takes encrypted message as a parameter.

```
def hack_caesar_cipher(message):
```

### Step 2:

Declare the LETTERS constant with the same symbols, our cipher supports.

```
LETTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\] !"#$%&\'()*+,-./0123456789abcdefghijklmnopqrstuvwxyz:;<=>?@^_`{|}~'
```

### Step 3:

Now we will loop through keys from 0 to size of symbols set or length of LETTERS. Then the program will try to decrypt the encrypted message string, using one key at a time, by looping over each letter in the encrypted message and subtracting the key from the letter index. Same as how we had decrypted in the last article.

### Step 4:

The program will print as output, all possible decryptions it achieves using each of the possible key values, essentially brute forcing it’s way to decrypt the cipher.

*Output will look like below :*

In the next article on Cryptology, we’ll learn about Affine Cipher, which is in some aspect, an extended version of the Caesar Cipher.

#### Source Code of the function :

*Keep coding! Have fun.*