Classical Ciphers Online — Caesar, Vigenère, Atbash & Rail Fence

Encoding
100% client-side. Processed locally in your browser using the Web Crypto API. Nothing is sent to any server.

How It Works

Classical ciphers provide NO real security. Caesar, Vigenère, Atbash, and Rail Fence can all be broken in seconds with frequency analysis or brute force. Use modern authenticated encryption (AES-256-GCM or ChaCha20-Poly1305) for actual data protection.

What Are Classical Ciphers?

Classical ciphers are pre-computer encryption methods that operate on letters rather than bits. They fall into two categories: substitution ciphers (replace letters with other letters — Caesar, Atbash, Vigenère) and transposition ciphers (rearrange letter positions — Rail Fence). While historically significant, all classical ciphers are vulnerable to frequency analysis and can be broken automatically.

When to Use Classical Ciphers

  • Learning cryptography — understand the fundamentals of substitution and transposition before moving modern algorithms
  • CTF competitions — capture-the-flag challenges frequently feature classical ciphers as puzzle components
  • Historical study — analyze encryption methods used by Julius Caesar, Mary Queen of Scots, and the Confederate Army
  • Puzzle solving — newspaper cryptograms and puzzle books use classical cipher techniques
  • Teaching frequency analysis — demonstrate why letter frequency distribution breaks simple substitution ciphers

Cipher Comparison

CipherTypeKeyBreakable byBest for
CaesarSubstitutionShift (1-25)Brute force (26 attempts)Learning, puzzles
VigenèrePolyalphabetic substitutionKeywordIndex of coincidence + frequency analysisCTF challenges
AtbashSubstitution (fixed)None (A-Z mirror)Immediate (no key)Historical study
Rail FenceTranspositionNumber of railsPattern analysisTeaching transposition

Standards Compliance

  • Historical — Caesar cipher (c. 100 BC), Atbash (c. 600 BC), Vigenère (1553 AD)
  • Not NIST/FIPS approved — classical ciphers do not meet modern cryptographic standards
  • Educational use only — for real security, use AES-256-GCM (FIPS 197) or ChaCha20-Poly1305 (RFC 8439)

Last updated:

Code Examples

JavaScript (Browser — Caesar Cipher)

// Caesar cipher encrypt/decrypt
function caesarEncrypt(text, shift) {
  return text.replace(/[a-z]/gi, c => {
    const base = c <= 'Z' ? 65 : 97;
    return String.fromCharCode((c.charCodeAt(0) - base + shift) % 26 + base);
  });
}

function caesarDecrypt(text, shift) {
  return caesarEncrypt(text, 26 - shift);
}

console.log(caesarEncrypt('HELLO', 3));   // KHOOR
console.log(caesarDecrypt('KHOOR', 3));   // HELLO

Python

def caesar(text, shift):
    result = []
    for c in text:
        if c.isalpha():
            base = ord('A') if c.isupper() else ord('a')
            result.append(chr((ord(c) - base + shift) % 26 + base))
        else:
            result.append(c)
    return ''.join(result)

print(caesar('HELLO', 3))   # KHOOR
print(caesar('KHOOR', -3))  # HELLO

Go

package main

import (
    "fmt"
    "strings"
)

func caesar(text string, shift int) string {
    var result strings.Builder
    for _, c := range text {
        if c >= 'a' && c <= 'z' {
            result.WriteRune(rune((int(c-'a')+shift+26)%26) + 'a')
       } else if c >= 'A' && c <= 'Z' {
            result.WriteRune(rune((int(c-'A')+shift+26)%26) + 'A')
        } else {
            result.WriteRune(c)
        }
    }
    return result.String()
}

func main() {
   
    fmt.Println(c, shift int) string {
    return caesar(text, -shift)
}

func main() {
    fmt.Println(caesar("HELLO", 3))   // KHOOR
    fmt.Println(caesarDecrypt("KHOOR", 3))  // HELLO
}

Rust

fn caesar_encrypt(text: &str, shift: i32) -> String {
    text.chars().map(|c| {
        if c.is_ascii_alphabetic() {
            let base = if c.is_uppercase() { b'A' } else { b'a' };
            let shifted = ((c as u8 - base) as i32 + shift).rem_euclid(26) as u8;
            (base + shifted) as char
        } else {
            c
        }
    }).collect()
}

fn main() {
    println!("{}", caesar_encrypt("HELLO", 3));  // KHOOR
}

Node.js

// Node.js — Vigenère cipher
function vigenereEncrypt(text, key) {
  let result = '';
  let keyIndex = 0;
  for (const c of text) {
    if (/[a-zA-Z]/.test(c)) {
      const base = c <= 'Z' ? 65 : 97;
      const shift = key.toUpperCase().charCodeAt(keyIndex % key.length) - 65;
      result += String.fromCharCode((c.charCodeAt(0) - base + shift) % 26 + base);
      keyIndex++;
    } else {
      result += c;
    }
  }
  return result;
}

console.log(vigenereEncrypt('HELLO', 'KEY'));  // RIJVS

Common Pitfalls

Using classical ciphers for real security. All classical ciphers can be broken in seconds with automated tools. For actual data protection, use AES-256-GCM or ChaCha20-Poly1305.
Ignoring case sensitivity. Classical ciphers typically preserve letter case but only operate on alphabetic characters. Digits, punctuation, and spaces pass through unchanged — this can leak information about the plaintext structure.
Short ciphertext is hard to break. Frequency analysis requires sufficient text (at least 20-30 characters for Caesar, 100+ for Vigenère). Very short messages may produce ambiguous results.
Confusing substitution and transposition. Substitution ciphers (Caesar, Vigenère, Atbash) change letter identities but preserve positions. Transposition ciphers (Rail Fence) preserve letter identities but change positions. Real classical systems often combined both.
Vigenère is not unbreakable. While Vigenère was once called "le chiffre indéchiffrable," the index of coincidence reveals the key length, then each column becomes a solvable Caesar cipher.

Security Notes

Frequency analysis is the key attack. English text has a stable letter profile: E appears ~12.7%, T ~9.1%, A ~8.2%. Substitution ciphers preserve this distribution, making them vulnerable to statistical analysis.
Index of Coincidence reveals key length. For Vigenère, the IC measures how "lumpy" the letter distribution is. English-like IC (~0.067) indicates the correct key length; random-like IC (~0.038) means the length is wrong.
Chi-squared scoring ranks candidates. For Caesar brute force, chi-squared distance against English letter frequencies identifies the most likely shift — the true shift almost always ranks first for texts of 12+ characters.
Use modern encryption for real security. AES-256-GCM provides authenticated encryption with associated data (AEAD), protecting both confidentiality and integrity. Classical ciphers provide neither.

Disclaimer

This tool is provided for educational and historical purposes only. Classical ciphers offer no real security against modern cryptanalysis. For actual data protection, use NIST-approved algorithms (AES-256-GCM, ChaCha20-Poly1305). All computation occurs entirely in your browser.

Further Reading

Related Concepts

Related Tools

Need modern encryption? Try the AES Encrypt/Decrypt tool. For secure hashing, see the SHA Hash Generator. To convert encoded data, use the Base64 Encode/Decode tool.

Frequently Asked Questions

Are classical ciphers secure enough for real use?

No. Caesar, Vigenère, Atbash, and Rail Fence all predate computers and can be broken in seconds with frequency analysis — the brute-force panel on this page demonstrates exactly why. They remain valuable for learning cryptography history, puzzle solving, and CTF competitions, but real protection requires modern authenticated encryption such as AES-256-GCM or ChaCha20-Poly1305.

How does frequency analysis break a Caesar cipher?

English text has a stable letter profile: E appears about 12.7% of the time, T about 9.1%, while Z barely reaches 0.1%. A Caesar shift moves that whole profile along the alphabet, so the most frequent letter in the ciphertext usually marks how far the text was rotated. This tool scores all 26 candidate shifts with the chi-squared distance against English and ranks them — the true shift almost always appears at the top for texts of a dozen letters or more.

How does the Vigenère key-length detection work?

It uses the index of coincidence (IC): the probability that two randomly chosen letters of the text are identical. Plain English sits near 0.067 while uniform random letters sit near 0.038. Splitting a Vigenère ciphertext into columns by a candidate key length produces English-like columns — and an English-like IC — exactly when the length matches the real key (or a multiple of it). The tool ranks lengths 1–16 and prefers the shortest statistically indistinguishable candidate, then breaks each column as an independent Caesar cipher to recover the keyword.

What is the difference between substitution and transposition ciphers?

Substitution ciphers replace letters but keep their positions: Caesar (shift), Atbash (mirror), and Vigenère (rotating keyword shift) are all substitution schemes, which is why letter frequencies survive encryption. Transposition ciphers like Rail Fence keep the letters but rearrange their order, so the letter profile stays flat-out identical to English — a dead giveaway that no substitution happened. Real classical systems often combined both.

What is the index of coincidence telling me?

The IC measures how "lumpy" a letter distribution is. English prose reuses a small alphabet unevenly, giving ≈ 0.0667; random letters give ≈ 0.0385 (1/26). In the Frequency Analysis tab, an IC near English means a monoalphabetic cipher (or plain text) — solvable by direct frequency matching. An IC near random means letters were masked by a polyalphabetic key such as Vigenère, and the Key Analysis panel is the next step.

Privacy: This tool runs entirely in your browser — nothing is uploaded or stored. · Disclaimer: For educational purposes only. Not professional security advice.

More in Encoding