Chris Spackman's NeoCities Page

Columnar Transposition Cipher

The Columnar Transposition cipher is a transposition cipher that rearranges letters by writing the message into rows of a grid and then reading the columns in a scrambled order determined by a keyword. Like the Rail Fence cipher, the letters themselves never change — only their positions. This cipher was widely used by military forces through both World Wars.

The Grid and Column Order Analogy

Imagine writing your message into a grid, left to right, row by row, where each column is labeled with a letter of the keyword. Then, instead of reading the grid left to right, you read the columns in alphabetical order of their keyword letters. The keyword determines the scrambled reading order.

Try It

Result

Grid

The message written into rows, with columns numbered by the alphabetical order of the keyword letters. Read the columns in numerical order (1, 2, 3, …) to produce the ciphertext.

Column Reading Order

Frequency Analysis

Like the Rail Fence cipher, the letter frequencies of the ciphertext are identical to the plaintext frequencies — because no letters were changed, only rearranged. Frequency analysis immediately tells an attacker that a transposition cipher was used.

How It Works

Encryption

  1. Choose a keyword (e.g., "ZEBRAS").
  2. Number the keyword letters by their alphabetical order. For "ZEBRAS": Z=6, E=2, B=1, R=4, A=0, S=5. (If letters repeat, number them left to right.)
  3. Write the plaintext into rows, each as wide as the keyword.
  4. If the last row is incomplete, pad it with X.
  5. Read the columns in numerical order (column 0 first, then column 1, and so on) to produce the ciphertext.

Decryption

To decrypt, reverse the process: figure out how many rows there are, fill the ciphertext back into the columns in numerical order, then read the grid row by row to recover the plaintext.

Why It Is Stronger Than Rail Fence

The Rail Fence cipher has very few possible keys — just the number of rails (usually 2–10). The Columnar Transposition cipher's key space depends on the keyword length: a keyword of length n gives n! possible column orderings. A 6-letter keyword gives 720 possibilities; a 10-letter keyword gives over 3.6 million. While still not enormous by modern standards, this is a significant improvement over the Rail Fence.

Things to Try

Disclaimer: these pages are educational demos provided as-is, with no warranty of any kind. The author is not responsible for any consequences arising from their use.

Send comments and bug reports to chris@chrisspackman.com.

Version 0.1 — Last updated: 2026-02-21

This page is Copyright © 2025 – 2026 Chris Spackman <chris@chrisspackman.com>.
This web site developed entirely on GNU/Linux with Free / Open Source Software.

This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Creative Commons License