Skip to content
DeepForgeby svx
All problems
HardInformation Theoryinfo-150

Rail Fence Decrypt

Problem

Decrypt a zigzag rail fence cipher. The plaintext was written down and up across `rails` rows and read row by row. Rebuild the zigzag position pattern, assign the ciphertext letters to positions in row order, and return the plaintext string.

Hint

With one rail the ciphertext is already the plaintext.

Test cases

case 1
in: ["WECRLTEERDSOEEFEAOCAIVDEN",3]
expected: "WEAREDISCOVEREDFLEEATONCE"
case 2
in: ["HLOOLELWRD",2]
expected: "HELLOWORLD"
case 3
in: ["AEBDFHCG",3]
expected: "ABCDEFGH"
Starter codePython
def rail_fence_decrypt(ciphertext, rails):
    # Your code here
    pass

3 test cases · run your code against them in the editor