Classic ciphers: Caesar, Vigenère, Playfair and more

Encrypt and decrypt with the classic ciphers: Caesar and ROT13, Vigenère, Atbash, Affine, Rail fence, Playfair, simple substitution and ROT47.

loading Classic ciphers: Caesar, Vigenère, Playfair and more
About this tool

What are classic ciphers?

Classic ciphers are the hand methods people used to hide messages before computers. You move letters, swap them, or mix them with a keyword. They are fun, they are in many puzzles and escape games, and they teach the basic ideas of cryptography: a key, an algorithm, and the way attackers read patterns in the text. This page runs nine of them in your browser: Caesar and ROT13, Vigenère, Atbash, Affine, Rail fence, Playfair, simple substitution, ROT47 and a Caesar breaker.

None of them is secure. A computer breaks every one of them in a moment, and some by hand in minutes. Use them for study, puzzles, games and teaching. Never use them to protect a password, a message or anything that matters. For real protection use modern encryption, for example the encryption tool or the PGP tool.

Here is how each one works. Caesar moves each letter a fixed number of places in the alphabet. Shift 13 is ROT13, which undoes itself. Atbash writes the alphabet backwards. Affine turns each letter x into a·x + b modulo 26, and a must have no common factor with 26. Vigenère uses a keyword, so the shift changes from letter to letter. Rail fence writes the text in a zigzag over some rails and reads it row by row. Playfair encrypts pairs of letters with a 5×5 square built from a keyword. Simple substitution replaces each letter by another from a shuffled alphabet key. ROT47 is like ROT13 but over all printable ASCII characters, so digits and symbols change too.

The Caesar breaker tries all 26 shifts and ranks them by how much the letters look like English, Portuguese or Spanish, using letter frequencies. It needs a few words of text to be sure. This is the same reasoning that defeated Vigenère in the 19th century. The text never leaves your browser. For other old-school encodings that are not encryption, see Morse code and the NATO alphabet.

How to use the classic ciphers

  1. Choose the method in Cipher:.
  2. Choose Direction:, Encrypt or Decrypt. ROT13, Atbash and ROT47 are their own inverse, so the direction does not matter for them.
  3. Type or paste your text in Text:. In the breaker, the box is called Encrypted text (Caesar):.
  4. Fill in the key that the method asks for: Shift (-25 to 25): for Caesar, Keyword: for Vigenère and Playfair, Multiplier a (coprime with 26): and Shift b (0 to 25): for Affine, Rails: for Rail fence, and Key (the 26 letters, each once): for substitution. The button Random key makes a substitution key for you.
  5. Read the Result and use Copy result.
  6. For the breaker, pick Language of the text:. The best guess appears as the result, and the list shows the other likely shifts. Use Use this shift to move one into the Caesar mode.
  7. For Playfair, look at the Playfair square to follow how each pair changes.

Examples

Caesar with shift 3

The famous pangram with shift 3, the shift Julius Caesar is said to have used:

THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG
WKH TXLFN EURZQ IRA MXPSV RYHU WKH ODCB GRJ

Decrypting the second line with shift 3 gives the first. With shift 13 (ROT13), Hello, World! becomes Uryyb, Jbeyq!, and applying it again returns the original.

Vigenère and Affine

Vigenère with the keyword LEMON turns ATTACKATDAWN into LXFOPVEFRNHR. The key advances only on letters, so Attack at dawn! becomes Lxfopv ef rnhr!. Affine with a = 5 and b = 8 turns AFFINE CIPHER into IHHWVC SWFRCP. If you choose a = 2, the tool refuses and lists the allowed values, because 2 shares a factor with 26.

Rail fence, Playfair and substitution

Rail fence with 3 rails turns WEAREDISCOVEREDFLEEATONCE into WECRLTEERDSOEEFEAOCAIVDEN. Playfair with the key PLAYFAIR EXAMPLE turns HIDE THE GOLD IN THE TREE STUMP into BMODZBXDNABEKUDMUIXMMOUVIF. Decrypting gives HIDETHEGOLDINTHETREXESTUMP: spaces are dropped and an X is added between doubled letters. Substitution with the key ZEBRASCDFGHIJKLMNOPQTUVWXY turns FLEE AT ONCE. WE ARE DISCOVERED! into SIAA ZQ LKBA. VA ZOA RFPBLUAOAR!.

Common errors and how to fix them

  • "The shift and the keys are whole numbers.": remove decimals or letters from the shift, multiplier and offset.
  • "Multiplier a must have no common factor with 26. The allowed values are {values}.": pick one of the listed values for a.
  • "The keyword needs at least one letter from A to Z.": a keyword of only digits or symbols does not work.
  • "The number of rails is a whole number from 2 up.": use 2 rails or more.
  • "The key has {length} letters; it needs all 26 letters of the alphabet.": complete the key, or use Random key.
  • "The letter {letter} appears twice in the key; each letter must appear exactly once.": remove the repeat and add a missing letter.
  • "To decrypt, the text needs an even number of letters (Playfair works on pairs).": the ciphertext was cut or has extra characters.
  • "The pair {pair} cannot be decrypted: Playfair never makes a pair of equal letters.": the text was not made by Playfair with this setup, or it was changed.
  • "The text has no letters from A to Z to analyse.": the breaker needs real letters.

Frequently asked questions

Is ROT13 encryption?

No. It is a fixed shift with no secret key, and anyone can undo it. People use it to hide spoilers or puzzle answers from a quick glance, not from a reader.

Why is Vigenère so much better than Caesar, and still broken?

A keyword spreads each letter over several alphabets, so simple frequency counts fail. But the key repeats, and methods from the 1800s find its length and then solve it like several Caesar ciphers. It is useful for learning that idea.

Can I use these ciphers to protect a password?

No. Treat everything here as a game. If you want to check how strong a password is, use the password strength analyser, and for secrets use real encryption.

Does the breaker always find the right shift?

Not always. With only a few letters the frequencies are not clear, and the right answer may not be first. Look at the list of guesses and pick the one that reads as a real sentence.

Report a problem