Wolfram Research

Function Repository Resource:

RailFenceDecipher

Source Notebook

Decipher a string enciphered by the rail fence cipher

Contributed by: Sander Huisman

ResourceFunction["RailFenceDecipher"][string,n]

deciphers string, enciphered using the rail fence cipher with n rails.

Details and Options

The value of n should be 2 or larger.
The letters ci zigzag on the n rails as follows:


Examples

Basic Examples

Decipher a string using the rail fence cipher with 3 rails:

In[1]:=
ResourceFunction["RailFenceDecipher"]["WECRLTEERDSOEEFEAOCAIVDEN", 3]
Out[1]=

Properties and Relations

The rail fence cipher is a transposition cipher; that is, the characters are scrambled rather than replaced:

In[2]:=
str = "WECRLTEERDSOEEFEAOCAIVDEN";
{Sort[Characters[ResourceFunction["RailFenceDecipher"][str, 3]]], Sort[Characters[str]]}
Out[3]=

The first character is not moved:

In[4]:=
str = "tshutijatsstsie";
Table[{i, ResourceFunction["RailFenceDecipher"][str, i]}, {i, 2, 15}] // Grid
Out[5]=

Neat Examples

Try using a varying number of rails to find the right number of rails:

In[6]:=
Grid[{#, ResourceFunction["RailFenceDecipher"][
     "WCLEESOFECAIVDENRDEEAOERT", #]} & /@ Range[2, 25]]
Out[6]=

Resource History

Related Resources

License Information