Athena Wiki

Caesar Cipher

cryptobeginner

Identify, brute-force, and decode Caesar (ROT) ciphers in CTF crypto challenges.

cryptocaesarrotrotationshiftclassical

Caesar Cipher

Caesar cipher is a simple substitution method where each letter is moved by a fixed number of positions. For example, with key 3, HELLO becomes KHOOR. In CTFs, this often appears as a first-layer obfuscation, so quick identification and brute force can reveal flags quickly.

How It Works

This section shows the core idea: shift letters forward to encrypt and backward to decrypt.

Mermaid diagram
Shift 3:
Plaintext:  A B C D E ... W X Y Z
Ciphertext: D E F G H ... Z A B C

HELLO → KHOOR (shift 3)
KHOOR → HELLO (shift -3, or shift 23)

Attack: Brute Force All 25 Shifts

If you do not know the key, try every possible shift and keep the output that looks readable.

Identify the cipher

First, confirm that letters are shifted in a consistent way.

Check: are only letters changed while symbols stay the same? IC ≈ 0.067 (IC is a score for how closely text matches normal English letter patterns). Does the challenge title mention "ROT" or "shift"?

Brute force all 25 shifts

Generate all shift results and inspect each one for meaningful plaintext.

Run the Python script or use dcode.fr/CyberChef to output all 25 candidate plaintexts.

Identify readable output

Choose the result that reads like normal language or contains a flag pattern.

Scan for English text. Look for the flag format flag{...} in the output.

Online Tools

Use these websites to quickly test Caesar shifts without writing your own script.

Tool / PlatformDescription
dcode.fr/caesarTry all shifts, shows English scoring
cryptii.comVisual Caesar decode
CyberChefUse Caesar/ROT brute force operations

Non-Standard Alphabets

Some challenges shift digits or mixed character sets, not just letters.

In these CTFs, apply the same idea to each character set (letters with mod 26, digits with mod 10):

The function below reads each character one by one and applies the key based on character type. Letters are shifted within A-Z or a-z using modulo 26, digits are shifted using modulo 10, and symbols/spaces are kept unchanged. Then the script asks for input text and key, runs the cipher, and prints the encrypted output.

def caesar_cipher(text, key):
  result = ""
  for c in text:
    if c.isalpha():
      base = ord('A') if c.isupper() else ord('a')
      result += chr((ord(c) - base + key) % 26 + base)
    elif c.isdigit():
      # Also rotate digits (0-9) by the same key modulo 10.
      result += str((int(c) + key) % 10)
    else:
      result += c
  return result

text = input("Enter text: ")
key = int(input("Enter Caesar key: "))

encrypted = caesar_cipher(text, key)
print("Encrypted:", encrypted)

Checklist

Use this quick list to avoid missing the most common Caesar solving steps.

  • Try a few common keys first
  • Brute-force all 25 shifts
  • Use dcode.fr or CyberChef for speed
  • Check: are digits rotated too (letters + numbers can both be shifted)
  • Mixed case? → shift letters only, preserve case

Last updated on

On this page