本文へスキップ

リソース · ガイド・記事

Rail Fence Cipher

レールフェンス暗号(ジグザグ暗号)を扱います。文字を複数のレールにまたがって斜めに上下させながら配置し、レールごとに読み出す転置式暗号です。

確認日

元のサイトを開く: Rail Fence Cipher (元のサイトを新しいタブで開きます)

ロードマップに追加

取り組んでいるロードマップにこのリソースを追加できます。自分用の追加リソースとして表示され、ロードマップの手順は変わらず、記録した手順数にも数えられません。

出典コンテンツの言語:英語

The rail fence cipher (also called a zigzag cipher) is a transposition cipher in which the message is split across a set of rails on a fence for encoding. The fence is populated with the message's characters, starting at the top left and adding a character on each position, traversing them diagonally to the bottom. Upon reaching the last rail, the direction should then turn diagonal and upwards up to the very first rail in a zig-zag motion. Rinse and repeat until the message is fully disposed across the fence. The encoded message is the result of concatenating the text in each rail, from top to bottom. From wikipedia, this is what the message WE ARE DISCOVERED. FLEE AT ONCE looks like on a 3-rail fence: The message can then be decoded by re-creating the encoded fence, with the same traversal pattern, except characters should only be added on one rail at a time. To illustrate that, a dash can be added on the rails that are not supposed to be populated yet. This is what the fence would look like after populating the first rail, the dashes represent positions that were visited but not populated.

PrepKit の概要

この概要は PrepKit 編集部がソースリポジトリをもとに執筆・確認したもので、リソース本文の引用ではありません。

対象
ソースにレベルの記載はありません
形式
リファレンス

扱っている内容

  • WE ARE DISCOVERED. FLEE AT ONCEを3本のレールで符号化する様子をテキストのグリッドで示し、得られる暗号文も掲載
  • ジグザグをたどり直してレールを一本ずつ埋める復号の手順。通過したが空の位置はダッシュで表す
  • 復号の際に次のレールを埋め始めるタイミング

使い方

PrepKit の学習アドバイスであり、ソースの主張ではありません。

任意のレール数に対応する符号化と復号をコードで書き、3本レールの暗号文を復号して元のメッセージが戻ることを確認してください。

範囲と制約

READMEには計算量の数値もコードもありません。外部資料はWikipediaのページとオンライン計算ツールだけです。

利用方法と形式

MITライセンスのtrekhleb/javascript-algorithmsリポジトリ内のGitHub上のREADMEで、英語で無料で読めます。

PrepKit が 2026/10/02 に確認しました。 リソースの出典のコミット: 85293e3e2b88

この概要の根拠
  • src/algorithms/cryptography/rail-fence-cipher/README.md

この項目を掲載しているページ

PrepKit ニュースレターを受け取る

任意です。PrepKit の利用には必要ありません。

メールアドレスの取り扱いについて