CipherMatrix

Vigenère Cipher Calculator

Encrypt or decrypt a message with a repeating keyword and see the key written under the text and the shift applied to each letter.

What is the Vigenère cipher?

The Vigenère cipher is a polyalphabetic substitution cipher: instead of one fixed shift for the whole message, each letter is shifted by an amount taken from a keyword. The keyword is repeated along the message, so the letter A in the key means shift 0, B means shift 1, and so on up to Z for shift 25. Each key letter therefore acts like a separate Caesar cipher.

For about three centuries the cipher was nicknamed "le chiffre indéchiffrable" (the indecipherable cipher). Friedrich Kasiski published a general method for breaking it in 1863, and Charles Babbage had found the same idea earlier without publishing it.

Encryption and decryption formulas

Number the letters A = 0, …, Z = 25 and let the key have m letters K(0), …, K(m − 1). Encryption is C(i) = (P(i) + K(i mod m)) mod 26 and decryption is P(i) = (C(i) − K(i mod m)) mod 26.

Worked example: encrypt ATTACKATDAWN with the key LEMON. The repeated key is LEMONLEMONLE. The first letter is A + L = 0 + 11 = 11, which is L. The second is T + E = 19 + 4 = 23, which is X. Continuing in the same way gives LXFOPVEFRNHR.

Why it is stronger than Caesar, and why it can still be broken

Because the same plaintext letter can become different cipher letters, the letter frequencies of the ciphertext are flattened and a simple frequency count no longer reveals the key. The security grows with the key length, and a random key as long as the message that is used only once is the unbreakable one-time pad.

With a short repeated keyword, however, the cipher is weak. Repeated words in the plaintext can line up with the same part of the key, producing repeated groups in the ciphertext. The distance between such groups reveals the key length m (Kasiski examination). Once m is known, every m-th letter was shifted by the same amount, and each of these groups is an ordinary Caesar cipher that frequency analysis solves.

Tips for using the calculator

Enter the text, the keyword and choose encrypt or decrypt.

  • The key may contain letters only; upper and lower case give the same shifts.
  • The key advances only on letters. Spaces and punctuation are copied unchanged and do not consume a key letter. Other programs may advance the key on every character, so results can differ from theirs.
  • A one-letter key turns the cipher into a Caesar cipher.

Worked examples

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

ATTACKATDAWN / LEMON

  • Mode: Encrypt
  • Text: ATTACKATDAWN
  • Keyword: LEMON
Ciphertext
LXFOPVEFRNHR
key LEMON (5 letters)
Convention used: the key advances only on letters. Spaces and punctuation are copied and do not use up a key letter. Some other programs advance the key on every character, which gives different output.

Step-by-step solution

Formula used
C(i) = (P(i) + K(i mod m)) mod 26
A = 0, …, Z = 25; m = key length = 5
  1. NoteNumber the letters and the key
    A = 0, B = 1, …, Z = 25.
    Key LEMON = (11, 4, 12, 14, 13), so the shifts repeat with period 5.
  2. NoteWrite the key under the text
    Each key letter is repeated to match the number of letters in the message.
    Plain : ATTACKATDAWN
    Key : LEMONLEMONLE
  3. CalculateAdd the key letter to each plaintext letter
    x + k, then mod 26
    #LetterxKey letterkx + kmod 26Result
    1A0L111111L
    2T19E42323X
    3T19M12315F
    4A0O141414O
    5C2N131515P
    6K10L112121V
    7A0E444E
    8T19M12315F
    9D3O141717R
    10A0N131313N
    11W22L11337H
    12N13E41717R
  4. CheckVerify by reversing
    Decrypting the result with the same key gives back the original text: ✓ yes
  5. ResultCiphertext
    LXFOPVEFRNHR

Decrypt LXFOPVEFRNHR

  • Mode: Decrypt
  • Text: LXFOPVEFRNHR
  • Keyword: LEMON
Plaintext
ATTACKATDAWN
key LEMON (5 letters)
Convention used: the key advances only on letters. Spaces and punctuation are copied and do not use up a key letter. Some other programs advance the key on every character, which gives different output.

Step-by-step solution

Formula used
P(i) = (C(i) − K(i mod m)) mod 26
A = 0, …, Z = 25; m = key length = 5
  1. NoteNumber the letters and the key
    A = 0, B = 1, …, Z = 25.
    Key LEMON = (11, 4, 12, 14, 13), so the shifts repeat with period 5.
  2. NoteWrite the key under the text
    Each key letter is repeated to match the number of letters in the message.
    Cipher: LXFOPVEFRNHR
    Key : LEMONLEMONLE
  3. CalculateSubtract the key letter from each cipher letter
    y − k, then mod 26
    #LetteryKey letterky − kmod 26Result
    1L11L1100A
    2X23E41919T
    3F5M12-719T
    4O14O1400A
    5P15N1322C
    6V21L111010K
    7E4E400A
    8F5M12-719T
    9R17O1433D
    10N13N1300A
    11H7L11-422W
    12R17E41313N
  4. CheckVerify by reversing
    Encrypting the result with the same key gives back the original text: ✓ yes
  5. ResultPlaintext
    ATTACKATDAWN

Mixed text, key KEY

  • Mode: Encrypt
  • Text: Meet me at noon, by the bridge!
  • Keyword: key
Ciphertext
Wicd qc kx lysl, lc rri zbmbqi!
key KEY (3 letters)
Convention used: the key advances only on letters. Spaces and punctuation are copied and do not use up a key letter. Some other programs advance the key on every character, which gives different output.

Step-by-step solution

Formula used
C(i) = (P(i) + K(i mod m)) mod 26
A = 0, …, Z = 25; m = key length = 3
  1. NoteNumber the letters and the key
    A = 0, B = 1, …, Z = 25.
    Key KEY = (10, 4, 24), so the shifts repeat with period 3.
  2. NoteWrite the key under the text
    Each key letter is repeated to match the number of letters in the message.
    Plain : MEETMEATNOONBYTHEBRIDGE
    Key : KEYKEYKEYKEYKEYKEYKEYKE
  3. CalculateAdd the key letter to each plaintext letter
    x + k, then mod 26
    #LetterxKey letterkx + kmod 26Result
    1M12K102222W
    2e4E488i
    3e4Y24282c
    4t19K10293d
    5m12E41616q
    6e4Y24282c
    7a0K101010k
    8t19E42323x
    9n13Y243711l
    10o14K102424y
    11o14E41818s
    12n13Y243711l
    13b1K101111l
    14y24E4282c
    15t19Y244317r
    16h7K101717r
    17e4E488i
    18b1Y242525z
    19r17K10271b
    20i8E41212m
    21d3Y24271b
    22g6K101616q
    23e4E488i
  4. CheckVerify by reversing
    Decrypting the result with the same key gives back the original text: ✓ yes
  5. ResultCiphertext
    Wicd qc kx lysl, lc rri zbmbqi!

Frequently asked questions

Is the Vigenère key case-sensitive?

No. The keys LEMON, lemon and Lemon all give the same shifts. Only the letters A to Z are allowed in the key.

Why do spaces not use up a key letter?

In the usual textbook convention the key moves only when a letter is enciphered. If another tool advances the key on spaces or punctuation too, its output will differ for texts that contain them.

What if the key is shorter than the message?

The key is simply repeated from the beginning as many times as needed. The shift for letter number i is the key letter at position i mod m.

How is the Vigenère cipher broken?

Find the key length with the Kasiski examination or the index of coincidence, split the ciphertext into that many columns, and solve each column as a Caesar cipher with frequency analysis.

Is a longer key always better?

A longer key is harder to attack, but the cipher remains weak against modern analysis unless the key is random, as long as the message and never reused.

Related calculators