Skip to main content
Basic Classic Symmetric Intermediate

The Nihilist Cipher

Learn about the Nihilist cipher, the 19th-century Russian revolutionary cipher that turns a Polybius square into a polyalphabetic system by adding coordinate numbers together instead of shifting letters.

PL
Pashalis Laoutaris
August 21, 2026
12 min read

Interactive Nihilist Cipher Visualizer

🔐 Nihilist Cipher Visualizer

5
Enter text and click a button to start!
P
+
K
=
R
HELLO

The Nihilist Cipher: Adding Coordinates Instead of Shifting Letters

Introduction

Named after the 19th-century Russian revolutionary movement that reportedly used it to evade Tsarist censors, the Nihilist cipher takes the Polybius square’s coordinate idea and combines it with the repeating-key concept behind Vigenère. But instead of shifting letters modulo 26, it does something more direct: it converts both the plaintext and the key into two-digit coordinate numbers, then simply adds them together with ordinary arithmetic. The result is a cipher whose ciphertext isn’t even letters. It’s a stream of numbers.

Table of Contents

How the Nihilist Cipher Works

The Nihilist cipher starts with a keyed 5×5 Polybius square, exactly like the Polybius square cipher already covered in this series. From there, it uses two keywords with two different jobs:

  1. The square keyword builds the grid itself (or the grid can be left unkeyed, using the plain alphabet in order).
  2. The additive keyword provides a repeating stream of numbers to add to the plaintext’s coordinate values, playing the same structural role a Vigenère keyword plays, just with addition instead of modular letter-shifting.

Interactive Visualizer

Try it above. Watch each plaintext letter’s coordinate value get highlighted in the square, then added to the corresponding additive-keyword letter’s value to produce the ciphertext number.

Computing a Nihilist Value

Every letter’s Nihilist value is its row number followed by its column number, treated as one two-digit number (not just concatenated digits, but ordinary arithmetic; this matters once addition enters the picture). This whole-number addition is the classic, historically standard form of the cipher. A few modern descriptions instead add the row and column digits separately (each modulo 5). That produces different-looking ciphertext but follows the same underlying idea. This article and the visualizer above use the classic whole-number version throughout. Using the standard grid:

    1  2  3  4  5
1   A  B  C  D  E
2   F  G  H  I/J K
3   L  M  N  O  P
4   Q  R  S  T  U
5   V  W  X  Y  Z

H sits at row 2, column 3, so its Nihilist value is 23. E sits at row 1, column 5, so its value is 15. These are exactly the same coordinate pairs the Polybius square produces. Nihilist’s twist is what happens next. As with the Polybius square this grid is built from, only 25 cells are available for 26 letters, so I and J conventionally share one cell (visible in the grid above). Spaces and punctuation are stripped from the message before this coordinate conversion happens, exactly as with every other grid-based cipher in this series.

A Worked Example

Using the standard unkeyed square and additive keyword “KEY”, encrypt “HELLO”:

The additive keyword repeats to match the plaintext length: K, E, Y, K, E, with Nihilist values 25, 15, 54, 25, 15.

Plain H E L L O
Plain value 23 15 31 31 34
Key letter K E Y K E
Key value 25 15 54 25 15
Ciphertext 48 30 85 56 49

Each ciphertext number is simply the plaintext value plus the key value: no modular wraparound at all. Working through the first letter concretely: H’s plaintext value is 23, and the first additive-keyword letter is K, whose value is 25 (row 2, column 5; K sits in row 2 alongside F, G, H, I/J). Adding them: 23 + 25 = 48, the first ciphertext number shown in the table.

“HELLO” → “48 30 85 56 49”

Decryption

Decryption reverses the addition: subtract each additive-keyword letter’s value from the corresponding ciphertext number to recover the plaintext letter’s coordinate value, then look that value up in the square.

Applying this to “48 30 85 56 49” with the same additive keyword “KEY”: 48 − 25 = 23 → H; 30 − 15 = 15 → E; 85 − 54 = 31 → L; 56 − 25 = 31 → L; 49 − 15 = 34 → O. Recovers “HELLO” exactly.

Nihilist vs. Vigenère

Both ciphers use a repeating key to vary the transformation applied to each plaintext letter, but they differ in exactly what gets combined and how:

  • Vigenère: works directly on letter positions (0-25) using modular addition (mod 26), so the result always wraps back around to another letter.
  • Nihilist: works on Polybius coordinate values (11-55) using plain, unbounded addition, so the result is a genuinely larger number rather than a letter. The ciphertext is numeric, not alphabetic.

This makes Nihilist ciphertext instantly recognizable as not being a substitution cipher output (it’s numbers, not letters). That numeric form is a mixed blessing for an attacker: it announces immediately that the cipher isn’t ordinary letter substitution, potentially saving them time. But it can also make manual frequency analysis feel less immediately familiar to work with than ciphertext letters, depending on the tools and habits a given analyst brings to the problem.

The “key” driving the addition can itself be strengthened further. Some historical Nihilist implementations added a third layer on top of the additive keyword. This was a separately-generated, independently-keyed sequence of digits, sometimes derived from a second keyword’s own Nihilist values. It was summed digit-by-digit with the first layer’s output, then added on top before producing the final ciphertext number. The intent was to push the effective key stream closer to genuine randomness, foreshadowing (without formally achieving) the perfect secrecy the one-time pad later proved requires a truly random, non-repeating key.

Pros and Cons Analysis

Advantages Disadvantages
Two Independent Keys: A square keyword and an additive keyword together create a larger combined keyspace than a single-keyword cipher Still Fundamentally Periodic: The additive keyword repeats just like a Vigenère keyword, so the same period-based weaknesses (Kasiski examination on the numeric stream) apply
Numeric Ciphertext: Doesn’t superficially resemble typical letter-substitution ciphertext, which had some practical advantage for concealment in its historical context No Modular Wraparound: Unlike Vigenère, ciphertext values grow without bound, which can itself leak structural information (e.g., value ranges hint at coordinate ranges)
Combines Two Cipher Families: A genuine hybrid of coordinate-based fractionation (Polybius) and repeating-key addition (Vigenère-style), historically notable for that combination Frequency Analysis Still Applies (with Effort): Because the key repeats, letters at the same key-position still share a fixed offset, enabling column-wise analysis similar to attacking Vigenère
Historically Notable: Associated with a specific, documented historical use case (Russian revolutionary correspondence), giving it genuine narrative interest beyond pure cryptography No Real-World Security Today: Like every classical cipher in this series, offers no protection against modern automated cryptanalysis

Cryptanalysis and Breaking the Nihilist Cipher

Despite its numeric disguise, Nihilist inherits Vigenère’s core structural weakness: the additive keyword repeats. So ciphertext values at the same position modulo the key length all share the same fixed offset from their plaintext values. An attacker can:

  1. Estimate the key length, using similar reasoning to Kasiski examination: look for repeated patterns in the numeric ciphertext stream at distances that are multiples of the key length.
  2. Group ciphertext values by key position, then analyze each group separately, since within one group every value differs from its plaintext by the exact same fixed additive offset.
  3. Use known or guessed Polybius-square value ranges (values only run from 11 to 55) to narrow down plausible offsets for each group, since only a limited set of additive shifts keep every recovered value within the valid coordinate range. The lack of modular wraparound leaks real information here. No valid coordinate value exceeds 55, so any ciphertext number above 100 can only have come from both the plaintext letter and the key letter sitting in row 5 (V, W, X, Y, or Z). A ciphertext value like 105, for instance, immediately narrows both the plaintext letter and the key letter down to just five candidates each, rather than the full 25.

This is meaningfully more laborious than attacking a simple monoalphabetic substitution. But once the key length is known, it follows the same fundamental logic that breaks every repeating-key cipher in this series.

Modern Relevance

The Nihilist cipher has no modern security role, but remains interesting for:

  • Its distinct historical narrative: a rare classical cipher with a specific documented political and historical context, rather than being purely an academic or military exercise.
  • Illustrating hybrid cipher design: combining a fractionation-style square (Polybius) with a repeating-key additive layer (Vigenère-style) previews the general pattern of layering multiple techniques that recurs throughout classical cryptography, including in ADFGVX.
  • A natural extension exercise: the third-layer variant covered above (an extra independently-keyed numeric sequence stacked on top of the additive keyword) is a useful mental stepping stone toward the one-time pad’s formal requirement of genuine, non-repeating randomness for perfect secrecy.

Python Implementation

The only real difference from a Polybius square is the arithmetic: plain addition of whole two-digit values instead of a letter lookup:

ALPHABET = 'ABCDEFGHIKLMNOPQRSTUVWXYZ'  # 25 letters, I/J share a cell

def generate_square(key=""):
    key = key.upper().replace('J', 'I')
    key = ''.join(c for c in key if c.isalpha())
    square = []
    seen = set()
    for char in key + ALPHABET:
        if char not in seen:
            seen.add(char)
            square.append(char)
    return square

def nihilist_value(square, char):
    row, col = divmod(square.index(char), 5)
    return (row + 1) * 10 + (col + 1)  # e.g. row 2, col 3 -> 23

def nihilist_encrypt(text, additive_key, square):
    text = text.upper().replace('J', 'I')
    text = ''.join(c for c in text if c.isalpha())
    additive_key = additive_key.upper().replace('J', 'I')
    values = []
    for i, char in enumerate(text):
        p_val = nihilist_value(square, char)
        k_val = nihilist_value(square, additive_key[i % len(additive_key)])
        values.append(p_val + k_val)  # no modulo: this can exceed 55
    return values

def nihilist_decrypt(values, additive_key, square):
    additive_key = additive_key.upper().replace('J', 'I')
    result = ''
    for i, val in enumerate(values):
        k_val = nihilist_value(square, additive_key[i % len(additive_key)])
        p_val = val - k_val
        row, col = divmod(p_val, 10)
        result += square[(row - 1) * 5 + (col - 1)]
    return result

if __name__ == "__main__":
    square = generate_square()  # unkeyed grid
    plaintext = "HELLO"
    additive_key = "KEY"

    ciphertext = nihilist_encrypt(plaintext, additive_key, square)
    recovered = nihilist_decrypt(ciphertext, additive_key, square)

    print(f"Plaintext:  {plaintext}")
    print(f"Ciphertext: {' '.join(map(str, ciphertext))}")
    print(f"Recovered:  {recovered}")

This reproduces the worked example above exactly: HELLO[48, 30, 85, 56, 49]HELLO, using the same additive keyword “KEY” and unkeyed square.

Limitations

This implementation is deliberately minimal:

  • No third-layer support. As the Nihilist vs. Vigenère section above describes, some historical implementations stacked a second, independently-keyed digit sequence on top of the additive keyword. This code only implements the two-key (square keyword plus additive keyword) version.
  • Ciphertext is a list of integers, not a string. Unlike every other cipher in this series, there’s no natural single-string representation, since values can be one, two, or three digits long; callers need to keep values space-separated or otherwise delimited, exactly as the visualizer displays them.
  • No validation that decrypted values are in range. nihilist_decrypt doesn’t check that p_val is between 11 and 55 before looking it up; a wrong key produces an IndexError or a nonsense letter rather than a clear error.
  • Not intended for real security. As the Cryptanalysis section above explains, the additive keyword still repeats, so this is breakable by the same category of attack that defeats Vigenère, regardless of implementation quality.

Conclusion

The Nihilist cipher takes two ideas already covered in this series: the Polybius square’s coordinate conversion and Vigenère’s repeating-key structure. It combines them through simple arithmetic addition rather than modular letter-shifting. The result is visually distinctive (numeric ciphertext instead of letters) and uses two independent keys. But it remains fundamentally periodic. Once an analyst accounts for the numeric rather than alphabetic output, it’s breakable by the same category of attack that defeats Vigenère. Its real interest today lies as much in its documented historical context as in its cryptographic design.

FAQ

What is the Nihilist cipher?

A cipher that converts each plaintext letter into its Polybius-square coordinate value (a two-digit number), then adds a repeating additive keyword’s corresponding coordinate values to produce numeric ciphertext, combining fractionation-style coordinates with a Vigenère-style repeating key.

Why is the ciphertext numbers instead of letters?

Because the cipher performs ordinary, unbounded addition on Polybius coordinate values rather than modular addition on letter positions, the result is a genuinely larger number each time, not a value that wraps back into the alphabet.

How is Nihilist different from Vigenère?

Vigenère adds letter positions modulo 26, always producing another letter. Nihilist adds Polybius coordinate values without any modular wraparound, always producing numeric ciphertext, and it also allows the underlying square itself to be independently keyed.

Is the Nihilist cipher secure?

No, not by modern standards. Its additive keyword still repeats periodically, making it vulnerable to the same category of key-length-detection and grouped-analysis attacks that break Vigenère, adapted for its numeric output.

Where does the name “Nihilist” come from?

It’s associated with the 19th-century Russian Nihilist revolutionary movement, which reportedly used this cipher (or a close variant) for secret communication.

References

  1. Wikipedia. “Nihilist cipher.” Available at: https://en.wikipedia.org/wiki/Nihilist_cipher

  2. Practical Cryptography. “Nihilist Cipher.” Available at: http://practicalcryptography.com/ciphers/nihilist-cipher/

  3. Singh, Simon. “The Code Book.” Doubleday, 1999.