# [OverTheWire] Krypton Level 2

So, it’s level 2 on Krypton Wargame, today we’ll work with substitution cipher, the Caesar Cipher.

### Level 2

Substitution ciphers are a simple replacement algorithm. In this example of a substitution cipher, we will explore a ‘monoalphebetic’ cipher. Monoalphebetic means, literally, “one alphabet” and you will see why.

This level contains an old form of cipher called a ‘Caesar Cipher‘. A Caesar cipher shifts the alphabet by a set number. For example:

plain: a b c d e f g h i j k … cipher: G H I J K L M N O P Q …

In this example, the letter ‘a’ in plaintext is replaced by a ‘G’ in the ciphertext so, for example, the plaintext ‘bad’ becomes ‘HGJ’ in ciphertext.

The password for level 3 is in the file krypton3. It is in 5 letter group ciphertext. It is encrypted with a Caesar Cipher. Without any further information, this cipher text may be difficult to break. You do not have direct access to the key, however you do have access to a program that will encrypt anything you wish to give it using the key. If you think logically, this is completely easy.

One shot can solve it!

Have fun.

Let’s see our ciphertext.

```krypton2@melissa:/krypton/krypton2\$ cat  krypton3
OMQEMDUEQMEK
```

We’ve one problem to decrypt this one, because we don’t know the used key, but we know that there are 25 keys [1, 25], so let’s try:

```#!/usr/bin/env python

class caesar(str):

"""An implementation of the Caesar cipher."""

def encipher(self, shift):
"""Encipher a plaintext and return it."""
ciphertext = []
for p in self:
if p.isalpha():
ciphertext.append(chr((ord(p) - ord('Aa'[int(p.islower())]) + shift) % 26 + ord('Aa'[int(p.islower())])))
else:
ciphertext.append(p)

return caesar(''.join(ciphertext))

def decipher(self, shift):
"""Decipher a ciphertext and return it."""
return self.encipher(-shift)

ciphertext = "OMQEMDUEQMEK"
for key in range(1, 26):
print "Ciphertext: %s \tKey as integer: %d \tPlainText: %s" % (ciphertext, key, caesar(ciphertext).decipher(key))
```

So, we’ll test the 25 possibilities.
I used also Cryptool, after getting the Key as an integer.

There we have it.