In this question, you are required to implement a program which can encrypt any plaintext into ciphertext with rail fence cipher and a program which can decrypt the ciphertext back into its original plaintext. Here is a description of the working principles of rail fence cipher: 25 marks.
Before encrypting any plaintext, an imaginary fence has to be defined beforehand. An imaginary fence has N rails. Each rail can hold at most M letters, where M is the length of the input message.
The input message can be considered as a sequence of letters. Those letters are first written on successive rails downwards and diagonally starting from the top rail until the bottom rail is reached. After one letter is written on a rail, the next letter will be written on the next rail. When the bottom rail is reached, the remaining letters are written on successive rails upwards and diagonally until the top rail is reached.
After that, the rails are read off one by one sequentially and the ciphertext can be derived.
Task A: Implement a program which first prompts the user to input the plaintext and the number of rails, then outputs the corresponding ciphertext.
Task B: Implement a program which prompts the user to input the ciphertext and the number of rails, then outputs the corresponding original plaintext.