Skip to content

↑↓ navigate ↵ open Esc close Search runs locally

Vigenère Cipher: Encoder, Decoder & Key Solver

Encrypt or decrypt with a keyword using the Vigenère, Beaufort or Autokey cipher. No key? Paste the ciphertext in Decrypt mode and the solver works out the key for you.

  • Runs in your browser
  • Nothing is uploaded
  • Free, no sign-up
0 chars
Vigenère
Runs in your browser. Nothing is uploaded. Tip: Decrypt finds the key from 40+ letters of ciphertext

How to use the Vigenère cipher tool#

  1. Choose Encrypt or Decrypt and type a Key (letters only; anything else is ignored).
  2. Type or paste your text. Only letters are changed; spaces, digits and punctuation stay, and the key only advances on letters.
  3. Pick a Variant: classic Vigenère, Beaufort (key minus letter, self-reciprocal) or Autokey (the message extends the key).
  4. Don't know the key? Choose Decrypt with at least 40 letters of ciphertext: the Key solver guesses the key length and each key letter, and lists the best candidates. Click one to use it.

Examples#

The classic textbook example

Input
ATTACKATDAWN
Output
LXFOPVEFRNHR

Key LEMON repeats under the message: A+L = L, T+E = X, T+M = F, and so on.

Spaces and case are kept

Input
attack at dawn
Output
lxfopv ef rnhr

The key only moves forward on letters, so spaces do not change the result.

Autokey variant

Input
attackatdawn
Output
qnxepvytwtwp

After the key runs out, the message itself is used as the key: QUEENLY + attackatdawn.

Crack a message without the key

Input
Eznwxfizpwlp ka ioi gtiramtg wu wvfvmramei qcmsioiipse dg iyeeundyqzpo xa mevw p msio bwhx fptn alv kvilrugl gleugz rhr lpltywkcvs. Msi vpgli tgvibvzga ioi Mkotuiig kxwlvt epz grnttk xyg qckitkxwlvrdtt jmgjmg, brkkt Roeinmh Iesdivl eef Ngpiutqro Oruqhrm jjwllh yqe iv figiz px.
Output
Cryptography is the practice of protecting information by transforming it into a form that only the intended reader can understand. For three centuries the Vigenere cipher was called the indecipherable cipher, until Charles Babbage and Friedrich Kasiski showed how to break it.

Delete the key and look at the Key solver under the tool: it recovers CIPHER from the ciphertext alone.

What is the Vigenère cipher?#

The Vigenère cipher encrypts text with a keyword: each letter is shifted by the matching letter of the key, which repeats along the message. With the key LEMON, the first letter is shifted by L (11), the second by E (4), the third by M (12), and so on. It is a set of Caesar ciphers used in turn, which makes it a polyalphabetic cipher.

It was described by Giovan Battista Bellaso in 1553 and later misattributed to Blaise de Vigenère. Because the same letter can be encrypted in different ways, simple frequency analysis fails, and for about three centuries it was known as le chiffre indéchiffrable, "the indecipherable cipher".

How it works#

Number the letters A = 0 to Z = 25. With plaintext letter P and key letter K:

plaintext
encrypt:  C = (P + K) mod 26decrypt:  P = (C − K) mod 26
PlaintextATTACKATDAWN
KeyLEMONLEMONLE
CiphertextLXFOPVEFRNHR

Historically, people used a 26 × 26 table called the tabula recta: find the plaintext letter's column and the key letter's row, and read the ciphertext letter where they meet.

Variants: Beaufort and Autokey#

VariantEncryptionKeyNotes
VigenèreC = (P + K) mod 26Repeating keywordThe classic form
BeaufortC = (K − P) mod 26Repeating keywordSelf-reciprocal: the same operation encrypts and decrypts
AutokeyC = (P + K) mod 26Keyword, then the plaintext itselfNo repeating key, so the solver below cannot crack it

How to break the Vigenère cipher#

A repeating key is the weakness. If the key has n letters, every nth letter of the message was shifted by the same amount, so each of those groups is just a Caesar cipher. The solver on this page breaks it in two steps:

  1. Find the key length. For each possible length from 1 to 20, the ciphertext is split into that many columns, and the index of coincidence of each column is measured: the chance that two random letters are the same. English text scores about 0.066, random letters about 0.038. The right key length makes every column look like English.
  2. Find each key letter. Each column is a Caesar cipher, so all 26 shifts are tried and the one whose letter frequencies are closest to English (chi-squared test) gives that key letter.

This is the modern version of the attack published by Friedrich Kasiski in 1863 (Charles Babbage had found a method earlier but did not publish it). It needs enough text: with fewer than about 10 letters per key letter, the guesses become unreliable, so always check the result.

Vigenère is not secure. As this page shows, it can be broken from the ciphertext alone. The only unbreakable version is the one-time pad, where the key is truly random, as long as the message and never reused.

Vigenère cipher in code#

JavaScript#

javascript
function vigenere(text, key, decrypt = false) {  const k = key.toUpperCase().replace(/[^A-Z]/g, '');  let j = 0;  return text.replace(/[a-z]/gi, (c) => {    const base = c <= 'Z' ? 65 : 97;    const shift = k.charCodeAt(j++ % k.length) - 65;    const x = c.charCodeAt(0) - base;    return String.fromCharCode(base + ((x + (decrypt ? 26 - shift : shift)) % 26));  });} vigenere('attack at dawn', 'LEMON');        // "lxfopv ef rnhr"vigenere('lxfopv ef rnhr', 'LEMON', true);  // "attack at dawn"

Python#

python
def vigenere(text: str, key: str, decrypt: bool = False) -> str:    k = [ord(c) - 65 for c in key.upper() if c.isalpha()]    out, j = [], 0    for c in text:        if c.isascii() and c.isalpha():            base = 65 if c.isupper() else 97            shift = -k[j % len(k)] if decrypt else k[j % len(k)]            out.append(chr((ord(c) - base + shift) % 26 + base))            j += 1        else:            out.append(c)    return ''.join(out)

Common errors and fixes#

  • Only the first few letters decrypt correctly

    The key is slightly wrong, or the sender's key advanced on spaces and punctuation too. This tool (like most) only advances the key on letters. Remove the spaces from the ciphertext and try again if you suspect the other convention.

  • The solver suggests a key that is the right one repeated, such as CIPHERCIPHER

    Multiples of the true key length fit too, and they decrypt the same way. The solver lists the shortest good candidate first; the shortest repeating part is the real key.

  • The solver's key is almost right but has a wrong letter

    The text is too short for frequency analysis on every column. Read the decryption, spot the column that looks wrong, and fix that key letter by hand: the rest of the message will tell you which letter fits.

  • Autokey ciphertext cannot be solved

    Autokey has no repeating key, so the column method does not apply. You need the keyword, or a guess of a word in the message.

Frequently asked questions#

How do I decrypt a Vigenère cipher without the key?

Choose Decrypt and paste at least 40 letters of ciphertext. The Key solver estimates the key length with the index of coincidence, then finds each key letter with frequency analysis, and lists the most likely keys. Click a key to apply it.

What is the difference between Vigenère and Caesar?

Caesar shifts every letter by the same amount. Vigenère changes the shift for each letter according to a keyword, so the same plaintext letter can become different ciphertext letters.

What is the Beaufort cipher?

A Vigenère variant that computes C = (K − P) mod 26 instead of (P + K). It is self-reciprocal, so the same operation and key encrypt and decrypt.

Does the key advance on spaces?

Not in this tool: the key only moves on letters, which is the most common convention. Spaces, digits and punctuation are copied unchanged.

Is the Vigenère cipher secure today?

No. It has been breakable since the 1800s, and a computer does it in milliseconds. Use it for puzzles and learning, not for real secrets.

Is my text uploaded?

No. Encryption, decryption and the solver all run in your browser.

Your next tool is one search away.

Free, private developer tools that run in your browser. No signup, nothing uploaded, no waiting.

Browse all tools

Tip: press Ctrl D to bookmark dev247.