1. 平文入力
2. 暗号化設定
鍵の設定
モードと整形
1. 暗号文入力
2. 復号設定
鍵の設定
モード設定
1. 文の入力
2. 鍵の設定
1段目の鍵で縦列転置し、その暗号文を2段目の鍵でもう一度縦列転置します。キーワード(英字)か数列(例: 3 1 4 2)を入れます。埋字は使いません(不完全モード)。
鍵
整形
1. 鍵のわからない暗号文
2. 総当たり
鍵長ごとに、列の並べ方をすべて試して復号し、英字の隣り合う2文字の組がどれだけ英語らしいかで順位を付けます。鍵長8までなら全部の並べ方(8列で40,320通り)を試せます。
範囲
手がかり
候補(英語らしい順)
| 順位 | 鍵長 | 鍵(数列) | 英語らしさ | 復号した文(先頭) | 操作 |
|---|
英語らしさは、英字の隣り合う2文字の組の log10 確率(100倍)の平均です。0に近いほど英語らしい値です。
3. 手で解く作業台
暗号文を鍵長の数の列に書き、列を左右に入れ替えて、行に英語が読めるかを確かめます(多重アナグラム法の手作業版)。隣り合う2列の組が英語らしいかを、列の間の印で示します。
鍵(数列):
復号した文:
📚 縦列転置式暗号とは
基本原理
縦列転置式暗号(Columnar Transposition Cipher)は、平文の文字の順序を体系的に並べ替える転置式暗号の一種です。
- 平文を横方向(行方向)にマトリクスへ書き込む
- 鍵に基づいて列を並べ替える
- 縦方向(列方向)に読み出して暗号文を生成
例:キーワード "KEY" での暗号化
平文: HELLO WORLD 鍵順: K=2, E=1, Y=3 マトリクス(書き込み): K E Y 2 1 3 ------- H E L L O W O R L D X X (Xはパディング) 列の並べ替え(鍵順で): E K Y 1 2 3 ------- E H L O L W R O L X D X 暗号文(縦読み): EORX HLOD LWLX
暗号の種類と特徴
①完全/不完全
完全モード:パディング文字で長方形にする
不完全モード:最終行が欠けたまま処理
②鍵の種類
キーワード:単語をアルファベット順で数値化
数列:直接数値で列順を指定(例: 3,1,4,2)
Myszkowski式:キーワードの同じ文字の列をまとめて、行ごとに左から読む
③二重転置
縦列を2回:縦列転置を2つの鍵で続けて行う
行と列:正方形の行と列を同じ鍵で並べ替える(ニヒリスト転置)
縦列を2回の方式は「二重転置」タブで試せます。
④経路式(ルート式)
斜め読み出し:対角線方向に読む
らせん読み出し:渦巻き状に読む
転置式暗号の歴史と背景
古代〜中世
スパルタのスキュタレー暗号など、初期の転置式暗号が登場。巻物を棒に巻きつけて文字を読む方式。
1880年代 - ロシアのニヒリスト
帝政ロシアの革命家たちが、ポリュビオス方陣を使う換字式の「ニヒリスト暗号」を使いました。転置式の「ニヒリスト転置」(正方形の行と列を同じ鍵で並べ替える)は、ゲインズの教科書『Cryptanalysis』(1939年)に載っている方式です。
第一次世界大戦
ドイツ軍が二重転置を使いました。鍵をあまり替えなかったため、フランスに繰り返し解読されました(フランス側の呼び名はÜbchi)。
第二次世界大戦
機械式の暗号機が主流になった一方で、二重転置は手作業の暗号として、オランダのレジスタンス、フランスのマキ、イギリスの特殊作戦執行部(SOE)などで使われました。
暗号学的特性
セキュリティ分析
- 拡散(Diffusion):文字の位置を分散させる効果あり
- 混同(Confusion):なし(文字の置換は行わない)
- 文字の頻度:平文と同じまま(頻度を数えると、換字式ではなく転置式だと見分けられる)
攻撃手法
- 総当たり攻撃:鍵長nに対してn!通りの並べ方を試す(n=8で40,320通り)
- 2文字の組の頻度:列を並べ替え、THやHEのような自然な2文字の組が多くなる並びを探す
- アナグラム攻撃:推測した単語が入るように列を並べ、鍵を推定する(同じ鍵の暗号文が複数あれば、まとめて並べ替える多重アナグラム法が使える)
縦列転置式暗号は教育目的や暗号学の基礎理解には優れていますが、現代のセキュリティ要件を満たしません。実用的な暗号化にはAESなどの現代暗号を使用してください。
他の古典暗号との比較
| 暗号方式 | 種類 | 操作 | 特徴 |
|---|---|---|---|
| 縦列転置式 | 転置 | 文字の並べ替え | 文字頻度は保存される |
| シーザー暗号 | 換字 | 文字のシフト | 単純な頻度分析で破れる |
| ヴィジュネル暗号 | 換字 | 複数のシフト | 多表式。鍵の長さがわかると頻度分析で破れる |
| レールフェンス暗号 | 転置 | ジグザグ配置 | レールの数が鍵のジグザグ転置 |
| プレイフェア暗号 | 換字 | 2文字組の置換 | 1文字の頻度は隠れるが、2文字の組の頻度で破れる |
実装のポイント
暗号化アルゴリズム
- 平文の前処理(スペース除去、大文字化など)
- 鍵から列順序を決定(キーワード→数値変換)
- マトリクスへの行方向書き込み
- 必要に応じてパディング追加
- 鍵順での列の並べ替え
- 列方向での読み出し
復号アルゴリズム
- 暗号文の長さと鍵から行数を計算(行数 = ceil(暗号文長 ÷ 列数))
- 各列の高さを決定(不完全モードでは注意)
- 鍵順にしたがって暗号文を列に配分
- 元の列順序に戻す
- 行方向で読み出して平文を復元
- パディングの除去(完全モードの場合)
ceil(シーリング)は天井関数とも呼ばれ、小数点以下を切り上げる数学関数です。
例:ceil(3.2) = 4、ceil(5.0) = 5、ceil(2.1) = 3
復号時の行数計算で使用し、暗号文がマトリクスに完全に収まるよう必要最小限の行数を求めます。
埋字の曖昧さ
完全モードでは、最終行の空きを埋字で埋めます。埋字は最大でも「列数−1」文字ですが、平文がもともと埋字と同じ文字で終わっていると、暗号文だけでは区別できません。
例:キーワード "KEY"・埋字 X
平文 "FO" → F O X(埋字) → 暗号文 OFX 平文 "FOX" → F O X(平文) → 暗号文 OFX どちらも同じ暗号文になる。 復号の「埋字を自動除去」は末尾のXを埋字とみなすので、結果は "FO"。
- 本ツールは、平文の最後の文字が埋字と同じときに、暗号化の時点で知らせる
- 復号では除いた埋字の数を表示し、表の中で埋字のセルを色分けする
- 実際の運用では、平文に出にくい文字や、意味のない文字(ヌル)を混ぜて埋めることがある。暗号化タブの「ランダムな英字(ヌル)で埋める」で試せる(Wikipediaの例はヌルにQKJEUを使っている)
関連するツール
「生成AIで作るセキュリティツール100」のほかのツールと組み合わせると、転置式暗号の性質が見えやすくなります。
練習問題
問題1:基本的な暗号化
平文 "MEET ME AFTER" をキーワード "CAT" で暗号化してみましょう。
解答を見る
キーワード: CAT → C=2, A=1, T=3 マトリクス: C A T 2 1 3 ----- M E E T M E A F T E R X 並べ替え後(A,C,T順): A C T 1 2 3 ----- E M E M T E F A T R E X 暗号文: EMFR MTAE EETX
問題2:不完全モードの復号
暗号文 "EEISV MERDC" を数列 "2,1,3" で復号してみましょう(不完全モード)。
解答を見る
暗号文長: 10文字、鍵長: 3 行数: ceil(10/3) = 4行 ※ceil:天井関数(切り上げ) 列の高さ: [4,3,3](10 = 3×3 + 1 なので、左の1列だけ4行) 読み出し順: 2列目(順1)→ 1列目(順2)→ 3列目(順3) 配分: 2列目(順1): EEI (3文字) 1列目(順2): SVME (4文字) 3列目(順3): RDC (3文字) 元の順序に戻す: 1 2 3 ----- S E R V E D M I C E · · 平文: SERVEDMICE(SERVED MICE)
Basic principle
The columnar transposition cipher is a transposition cipher: it rearranges the order of the plaintext letters in a systematic way.
- Write the plaintext into a matrix row by row
- Reorder the columns according to the key
- Read the ciphertext column by column
Example: encrypting with the keyword "KEY"
Plaintext: HELLO WORLD Key order: K=2, E=1, Y=3 Matrix (written row by row): K E Y 2 1 3 ------- H E L L O W O R L D X X (X is padding) Columns reordered by the key: E K Y 1 2 3 ------- E H L O L W R O L X D X Ciphertext (read down the columns): EORX HLOD LWLX
Types and features
1. Complete / incomplete
Complete: pad the last row to make a rectangle
Incomplete: leave the last row short
2. Kinds of keys
Keyword: number the letters of a word in alphabetical order
Number sequence: give the column order directly (e.g. 3,1,4,2)
Myszkowski: read columns with the same keyword letter together, row by row from the left
3. Double transposition
Two columnar passes: apply columnar transposition with two keys in a row
Rows and columns: reorder both the rows and the columns of a square with the same key (Nihilist transposition)
You can try the two-pass method in the Double transposition tab.
4. Route ciphers
Diagonal reading: read along the diagonals
Spiral reading: read in a spiral
History
Antiquity to the Middle Ages
Early transposition ciphers such as the Spartan scytale, where a strip is wound around a rod and the text is read along it.
1880s - Russian Nihilists
Revolutionaries in Tsarist Russia used the "Nihilist cipher", a substitution cipher based on a Polybius square. The transposition known as the "Nihilist transposition" (reordering both the rows and the columns of a square with the same key) is described in Gaines' textbook Cryptanalysis (1939).
World War I
The German army used double transposition. Because the keys were changed infrequently, the French solved it regularly (they called it Übchi).
World War II
While cipher machines became mainstream, double transposition was used as a hand cipher by the Dutch resistance, the French Maquis and the British Special Operations Executive (SOE), among others.
Cryptographic properties
Security analysis
- Diffusion: spreads the positions of the letters
- Confusion: none (no letter is substituted)
- Letter frequencies: the same as in the plaintext (counting them tells a transposition from a substitution)
Attacks
- Brute force: try all n! column orders for a key length n (40,320 orders for n=8)
- Letter pair frequencies: reorder the columns to find the arrangement with the most natural pairs such as TH and HE
- Anagramming: arrange the columns so that a guessed word appears, and infer the key (with several ciphertexts under the same key, they can be rearranged together: multiple anagramming)
The columnar transposition cipher is good for education and for learning the basics of cryptography, but it does not meet modern security requirements. Use modern ciphers such as AES for real encryption.
Comparison with other classical ciphers
| Cipher | Type | Operation | Notes |
|---|---|---|---|
| Columnar transposition | Transposition | Reorders letters | Letter frequencies are preserved |
| Caesar cipher | Substitution | Shifts letters | Broken by simple frequency analysis |
| Vigenère cipher | Substitution | Several shifts | Polyalphabetic. Broken by frequency analysis once the key length is known |
| Rail fence cipher | Transposition | Zigzag placement | A zigzag transposition whose key is the number of rails |
| Playfair cipher | Substitution | Substitutes letter pairs | Hides single-letter frequencies but is broken by pair frequencies |
Implementation notes
Encryption
- Preprocess the plaintext (remove spaces, convert to uppercase, and so on)
- Determine the column order from the key (keyword to numbers)
- Write the text into the matrix row by row
- Add padding if needed
- Reorder the columns by the key
- Read column by column
Decryption
- Compute the number of rows from the ciphertext length and the key (rows = ceil(length ÷ columns))
- Determine the height of each column (take care in incomplete mode)
- Distribute the ciphertext to the columns in key order
- Put the columns back in their original order
- Read row by row to recover the plaintext
- Remove the padding (in complete mode)
ceil (the ceiling function) rounds a number up to the next integer.
Examples: ceil(3.2) = 4, ceil(5.0) = 5, ceil(2.1) = 3
It is used when decrypting to find the smallest number of rows that holds the whole ciphertext.
Padding ambiguity
In complete mode the empty cells of the last row are filled with the padding letter. There are at most (columns − 1) padding letters, but if the plaintext itself ends with the padding letter, the ciphertext alone cannot tell them apart.
Example: keyword "KEY", padding X
Plaintext "FO" → F O X(padding) → ciphertext OFX Plaintext "FOX" → F O X(plaintext) → ciphertext OFX Both give the same ciphertext. "Remove padding automatically" treats the final X as padding, so the result is "FO".
- This tool warns at encryption time when the last plaintext letter is the same as the padding letter
- When decrypting, it shows how many padding letters were removed and colors those cells in the matrix
- In practice, padding is sometimes made of letters that rarely end a message, or of meaningless letters (nulls). Try "Pad with random letters (nulls)" in the Encrypt tab (the Wikipedia example uses QKJEU as nulls)
Related tools
Combining this tool with others from "100 Security Tools with Generative AI" makes the properties of transposition ciphers easier to see.
Exercises
Exercise 1: basic encryption
Encrypt the plaintext "MEET ME AFTER" with the keyword "CAT".
Show answer
Keyword: CAT → C=2, A=1, T=3 Matrix: C A T 2 1 3 ----- M E E T M E A F T E R X Reordered (A, C, T): A C T 1 2 3 ----- E M E M T E F A T R E X Ciphertext: EMFR MTAE EETX
Exercise 2: decryption in incomplete mode
Decrypt the ciphertext "EEISV MERDC" with the number sequence "2,1,3" (incomplete mode).
Show answer
Length: 10, key length: 3 Rows: ceil(10/3) = 4 (ceil rounds up) Column heights: [4,3,3] (10 = 3×3 + 1, so only the leftmost column has 4 rows) Reading order: column 2 (1st) → column 1 (2nd) → column 3 (3rd) Distribution: Column 2 (1st): EEI (3 letters) Column 1 (2nd): SVME (4 letters) Column 3 (3rd): RDC (3 letters) Back in the original order: 1 2 3 ----- S E R V E D M I C E · · Plaintext: SERVEDMICE (SERVED MICE)