Vigenère cipher · 04 The maths

Vigenère cipher: the maths

The formulas of the Vigenère cipher in modular arithmetic, the key space and why the repetition of the key is its weakness.

Numbering the letters from A = 0 to Z = 25, encryption and decryption are written with modular arithmetic.

  1. 01
    Encryption

    C_i = (P_i + K_(i mod m)) mod 26, where P is the text, K the key and m its length.

  2. 02
    Decryption

    P_i = (C_i − K_(i mod m)) mod 26.

  3. 03
    Key space

    With an m-letter key there are 26^m possible keys: with 10 letters over 140 trillion.

  4. 04
    Structure

    The letters in positions i, i + m, i + 2m… are encrypted with the same key letter, that is with the same Caesar cipher.

Why the key space is not enough

A huge number of keys seems to guarantee security, but the cipher’s structure means you do not have to try them all. Once the length m is found, the text splits into m columns, each encrypted with a simple shift: each is solved with frequency analysis, like a Caesar cipher.

Continue with
05 Weaknesses and attacks

Vigenère cipher: weaknesses and attacks

The Kasiski method, Friedman’s index of coincidence and column-by-column frequency analysis: how the Vigenère cipher is broken.

↑