Skip to content

Latest commit

 

History

History
50 lines (33 loc) · 1.92 KB

README.md

File metadata and controls

50 lines (33 loc) · 1.92 KB

railFenceCipher

Rail Fence Cipher: Encoding and Decoding

中文 README

node nodejs build Coverage Status ISC

Rail fence cipher

In the rail fence cipher, the plain text is written downwards and diagonally on successive "rails" of an imaginary fence, then moving up when we reach the bottom rail. When we reach the top rail, the message is written downwards again until the whole plaintext is written out. The message is then read off in rows. For example, if we have 3 "rails" and a message of 'WE ARE DISCOVERED. FLEE AT ONCE', the cipherer writes out:

W . . . E . . . C . . . R . . . L . . . T . . . E
. E . R . D . S . O . E . E . F . E . A . O . C .
. . A . . . I . . . V . . . D . . . E . . . N . .

Then reads off to get the ciphertext:

WECRLTEERDSOEEFEAOCAIVDEN

Note that this particular example does NOT use spaces separating the words. The decipherer will need to add them based on context. If spaces are shown in the ciphertext, then they must be included in the count of letters to determine the width of the solution grid.

install

With npm do:

npm install railFenceCipher

var railfencecipher = require("railfencecipher")

For use in web browsers do:

<script src="railFenceCipher.min.js"></script>

methods

Encoding

railfencecipher.encodeRailFenceCipher('WEAREDISCOVEREDFLEEATONCE',3)
//WECRLTEERDSOEEFEAOCAIVDEN

Encoding

railfencecipher.decodeRailFenceCipher('WECRLTEERDSOEEFEAOCAIVDEN',3)
//WEAREDISCOVEREDFLEEATONCE