CipherMatrix

Caesar Cipher Encoder, Decoder and Brute-Force Solver

Shift every letter of a message by a fixed number of places to encrypt it, undo the shift to decrypt it, or try all 25 shifts when the key is unknown.

What is the Caesar cipher?

The Caesar cipher is one of the oldest and simplest substitution ciphers. Each letter of the plaintext is replaced by the letter a fixed number of positions further along the alphabet. The Roman historian Suetonius reports that Julius Caesar used a shift of three to protect military messages, so with a shift of 3 the letter A becomes D, B becomes E, and Z wraps around to C.

Because only 25 non-trivial shifts exist, the cipher offers no real security today. It is still the standard first example in cryptography courses, because it introduces keys, encryption, decryption and modular arithmetic in a form that can be done by hand.

The mathematics: arithmetic modulo 26

Number the letters A = 0, B = 1, …, Z = 25. For a shift k, encryption is E(x) = (x + k) mod 26 and decryption is D(y) = (y − k) mod 26. The remainder after division by 26 is what makes the alphabet wrap around. For example, Y has the number 24, and with k = 3 the sum is 27; since 27 mod 26 = 1, the cipher letter is B.

Decryption is the same operation with the opposite shift, because shifting back by k is the same as shifting forward by 26 − k. ROT13 is the special case k = 13: since 13 + 13 = 26, applying it twice returns the original text, so one function both encrypts and decrypts.

How to break a Caesar cipher

With only 25 possible keys, the simplest attack is brute force: decrypt with every shift and read the results until one makes sense. The brute-force mode of this calculator does exactly that and also ranks the candidates by comparing their letter frequencies with English, where E, T, A, O and N are the most common letters.

The statistical ranking works well for sentences but can fail for very short messages, so always scan the table yourself.

Using this calculator

Choose a mode, type your text and set the shift. The result updates as you type.

  • Upper- and lower-case letters keep their case; digits, spaces and punctuation are not changed.
  • The step table lists, for each letter, its number x, the sum x + k (or y − k when decrypting), the value mod 26 and the resulting letter.
  • Use the brute-force mode to attack a ciphertext whose shift you do not know.

Worked examples

These examples are computed by the same engine as the calculator above, so you can compare each step with your own working.

Encrypt, shift 3

  • Mode: Encrypt
  • Text: Hello, World!
  • Shift k (0–25): 3
Ciphertext
Khoor, Zruog!
shift k = 3 (encryption)

Step-by-step solution

Formula used
E(x) = (x + k) mod 26
A = 0, B = 1, …, Z = 25; k = 3
  1. NoteNumber the letters
    A = 0, B = 1, …, Z = 25. Upper- and lower-case letters use the same numbers and keep their case; spaces, digits and punctuation are copied unchanged.
    Shift k = 3, 10 letters to convert.
  2. NoteAlphabet mapping (plain → cipher)
    Plain letter : ABCDEFGHIJKLMNOPQRSTUVWXYZ
    Cipher letter: DEFGHIJKLMNOPQRSTUVWXYZABC
  3. CalculateConvert every letter
    x → (x + 3) mod 26
    #Letterxx + kmod 26Result
    1H71010K
    2e477h
    3l111414o
    4l111414o
    5o141717r
    6W222525Z
    7o141717r
    8r172020u
    9l111414o
    10d366g
  4. CheckVerify by reversing
    Decrypting the result with the same shift gives back the original text: ✓ yes
  5. ResultCiphertext
    Khoor, Zruog!

Decrypt ROT13

  • Mode: Decrypt (known shift)
  • Text: URYYB JBEYQ
  • Shift k (0–25): 13
Plaintext
HELLO WORLD
shift k = 13 (decryption)
Shift 13 is ROT13: applying it twice returns the original text, so encryption and decryption are the same operation.

Step-by-step solution

Formula used
D(y) = (y − k) mod 26
A = 0, B = 1, …, Z = 25; k = 13
  1. NoteNumber the letters
    A = 0, B = 1, …, Z = 25. Upper- and lower-case letters use the same numbers and keep their case; spaces, digits and punctuation are copied unchanged.
    Shift k = 13, 10 letters to convert.
  2. NoteAlphabet mapping (cipher → plain)
    Cipher letter: ABCDEFGHIJKLMNOPQRSTUVWXYZ
    Plain letter : NOPQRSTUVWXYZABCDEFGHIJKLM
  3. CalculateConvert every letter
    y → (y − 13) mod 26
    #Letteryy − kmod 26Result
    1U2077H
    2R1744E
    3Y241111L
    4Y241111L
    5B1-1214O
    6J9-422W
    7B1-1214O
    8E4-917R
    9Y241111L
    10Q1633D
  4. CheckVerify by reversing
    Encrypting the result with the same shift gives back the original text: ✓ yes
  5. ResultPlaintext
    HELLO WORLD

Brute force

  • Mode: Brute force (unknown shift)
  • Text: WKLV LV D VHFUHW PHVVDJH
Most likely plaintext
THIS IS A SECRET MESSAGE
shift k = 3 (guess from English letter frequencies)
The best guess is chosen by comparing letter frequencies with English (chi-squared test). Always read the candidates yourself: the guess is only a hint.

Step-by-step solution

Formula used
D(y) = (y − k) mod 26 for every k = 1, 2, …, 25
A = 0, B = 1, …, Z = 25
  1. NoteWhy brute force works
    A Caesar cipher has only 25 non-trivial keys (k = 0 leaves the text unchanged).
    So we simply try every shift and look for the one that gives readable text.
  2. CalculateDecrypt with every shift k = 1 … 25
    candidate(k) = D(ciphertext) with D(y) = (y − k) mod 26
    Shift kCandidate plaintextChi-squaredGuess
    1VJKU KU C UGETGV OGUUCIG153.6
    2UIJT JT B TFDSFU NFTTBHF185.3
    3THIS IS A SECRET MESSAGE21.6◀ best guess
    4SGHR HR Z RDBQDS LDRRZFD358.4
    5RFGQ GQ Y QCAPCR KCQQYEC1360.3
    6QEFP FP X PBZOBQ JBPPXDB553.7
    7PDEO EO W OAYNAP IAOOWCA33.8
    8OCDN DN V NZXMZO HZNNVBZ1148.8
    9NBCM CM U MYWLYN GYMMUAY99.7
    10MABL BL T LXVKXM FXLLTZX650.3
    11LZAK AK S KWUJWL EWKKSYW291.4
    12KYZJ ZJ R JVTIVK DVJJRXV1216.6
    13JXYI YI Q IUSHUJ CUIIQWU417.2
    14IWXH XH P HTRGTI BTHHPVT169.8
    15HVWG WG O GSQFSH ASGGOUS131.5
    16GUVF VF N FRPERG ZRFFNTR155.7
    17FTUE UE M EQODQF YQEEMSQ862.2
    18ESTD TD L DPNCPE XPDDLRP97.1
    19DRSC SC K COMBOD WOCCKQO130.4
    20CQRB RB J BNLANC VNBBJPN279.1
    21BPQA QA I AMKZMB UMAAIOM334.5
    22AOPZ PZ H ZLJYLA TLZZHNL1742.3
    23ZNOY OY G YKIXKZ SKYYGMK467.5
    24YMNX NX F XJHWJY RJXXFLJ1365.4
    25XLMW MW E WIGVIX QIWWEKI255.6
  3. ResultPick the readable candidate
    Most likely: shift 3 → THIS IS A SECRET MESSAGE

Frequently asked questions

What shift did Julius Caesar use?

According to Suetonius, Caesar shifted each letter by three places, so A became D. Other Roman sources mention a shift of four used by Augustus.

Is the Caesar cipher secure?

No. There are only 25 usable keys, so an attacker can try them all in seconds, and letter-frequency analysis breaks it even without trying every key. It is useful for learning, not for protecting real data.

What happens to spaces, digits and punctuation?

They are left unchanged. Only the 26 letters A to Z are shifted, and each letter keeps its upper or lower case.

How do I decrypt a Caesar cipher when I do not know the shift?

Switch to the brute-force mode. It decrypts the text with all 25 shifts and highlights the candidate whose letter frequencies look most like English.

What is ROT13?

ROT13 is the Caesar cipher with a shift of 13. Because the alphabet has 26 letters, applying ROT13 twice gives back the original text.

Related calculators