Rotating Grille Cipher
This is the third mission on classical cryptography. In this mission we will encrypt a message using a rotating grille.
Rotating grille cipher is a transposition cipher that uses a special square sheet of cardboard (the grille ) with holes cut in it. To encrypt a message, sender must place the grille on an empty sheet of paper and write letters of the plaintext into the holes left to right, top to bottom. After filling all the holes, the grille is rotated 90 degrees clockwise (the holes move to empty spaces) and the process continues. After the grille was rotated 2 more times, there should be no empty spaces on the paper; if the message is not finished, the algorithm is repeated on the next sheet.
For example, here's what encrypting the line Meet me at twelve PM would look like (we'll use a grille of size 4x4):
After the encryption, the ciphertext reads as tmmveeewepeatlmt .
In this task you are given a message and a key (4x4 square grille); length of the message is divisible by 16. You need to encrypt a message with the rotating grille cipher. There is a problem, though: some of the keys are defective. ...