Rail Fence Cipher: Encoding and Decoding
Description:
Create two functions to encode and then decode a string using the Rail Fence Cipher. This cipher is used to encode a string by placing each character successively in a diagonal along a set of "rails". First start off moving diagonally and down. When you reach the bottom, reverse direction and move diagonally and up until you reach the top rail. Continue until you reach the end of the string. Each "rail" is then read left to right to derive the encoded string.
For example, the string "WEAREDISCOVEREDFLEEATONCE"
could be represented in a three rail system as follows:
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
The encoded string would be:
WECRLTEERDSOEEFEAOCAIVDEN
Write a function/method that takes 2 arguments, a string and the number of rails, and returns the ENCODED string.
Write a second function/method that takes 2 arguments, an encoded string and the number of rails, and returns the DECODED string.
For both encoding and decoding, assume number of rails >= 2 and that passing an empty string will return an empty string.
Note that the example above excludes the punctuation and spaces just for simplicity. There are, however, tests that include punctuation. Don't filter out punctuation as they are a part of the string.
Similar Kata:
Stats:
Created | Mar 12, 2017 |
Published | Mar 15, 2017 |
Warriors Trained | 24077 |
Total Skips | 5896 |
Total Code Submissions | 71539 |
Total Times Completed | 8989 |
JavaScript Completions | 2068 |
Ruby Completions | 289 |
Python Completions | 3635 |
Java Completions | 901 |
Haskell Completions | 142 |
C++ Completions | 843 |
C# Completions | 659 |
Go Completions | 248 |
Rust Completions | 228 |
PHP Completions | 181 |
COBOL Completions | 8 |
VB Completions | 7 |
Total Stars | 1126 |
% of votes with a positive feedback rating | 96% of 1286 |
Total "Very Satisfied" Votes | 1187 |
Total "Somewhat Satisfied" Votes | 90 |
Total "Not Satisfied" Votes | 9 |
Total Rank Assessments | 9 |
Average Assessed Rank | 3 kyu |
Highest Assessed Rank | 3 kyu |
Lowest Assessed Rank | 4 kyu |