Reverse Rail Fence Cipher[Rail] This page defines a Reverse Rail Cipher coding. For this we add a number of "rails", and add the characters in sequence, such as for three rails (taken from Wikipedia): 'WE ARE DISCOVERED. FLEE AT ONCE', gives: 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 . . to give: WECRL TEERD SOEEF EAOCA IVDEN Try an example of "WECRL TEERD SOEEF EAOCA IVDEN": Try which should give "WEAREDISCOVEREDFLEEATONCE". See the Wiki page for this example (here). Note enter a "*" for a space, as we get rid of spaces in the cipher text. |
Examples
Coding
public static string reverse_rail(string rail) { int i = 1; char[] rtn = new char[rail.Length]; int j = 0; rail = rail.Replace(" ", ""); for (i = 0; i < rail.Length; i += 4) { rtn[i] = rail[j]; j++; } for (i = 1; i < rail.Length; i += 2) { rtn[i]= rail[j]; j++; } for (i = 2; i < rail.Length; i += 4) { rtn[i] = rail[j]; j++; } string s = new string(rtn); return (s); }