The Vigenère cipher was a simple polyalphabetic cipher that basically applied one of several Caesar ciphers, according to a key. Bascially the letters in the key indicate which shifted alphabet to use. To that end there was a simple tool, called the Vigenère square:
Here each row is a separate alphabet, starting with the corresponding letter of the key. The columns then are used to determine the ciphered letter. Decryption works in very much the same fashion, only vice-versa.
Suppose we want to encrypt the string
CODEGOLF. We also need a key. In this case the key shall be
FOOBAR. When the key is shorter than the plaintext we extend it by repetition, therefore the actual key we use is
FOOBARFO. We now look up the first letter of the key, which is
F to find the alphabet. It starts, perhaps unsurprisingly, with
F. Now we find the column with the first letter of the plaintext and the resulting letter is
H. For the second letter we have
O as the key letter and the plain text letter, resulting in
C. Continuing that way we finally get
Your task now is to decipher messages, given a key. However, since we have outgrown the 16th century and have computers we should at least support a slightly larger alphabet:
The construction of the Vigenère square is still very much the same and the cipher still works in the same way. It's just a bit ... unwieldy to give here in full.
Input is given on standard input as two separate lines of text, each terminated by a line break. The first line contains the key while the second contains the ciphertext.
A single line, containing the deciphered message.
Since encryption is sometimes regarded as a weapon, the code should be short to facilitate easy smuggling. The shorter the better, as it reduces the likelihood of discovery.
Sample input 1
Sample output 1
Sample input 2
Sample output 2
A week has passed. The currently shortest solution has been accepted. For those interested, in our contest we had the following submissions and lengths:
130 – Python
146 – Haskell
195 – C
197 – C
267 – VB.NET
And our own solutions that weren't ranked with the others:
108 – Ruby
139 – PowerShell