eolymp
bolt
Try our new interface for solving problems
Problems

Vigenere Cipher Encryption

Vigenere Cipher Encryption

One of the oldest and most common encryption algorithms is Vigenere Cipher. It is quite an old thing - a similar encryption was first described in 1553 by Giovan Battista Bellaso and improved in 1586 by Blaise de Vigenere.

Vigenere encryption produces a single letter of ciphertext for each letter of plaintext, combining one plaintext letter with one single letter of a key on the corresponding position. If the key is shorter than the plaintext, it is simply repeated as needed, e.g. for a key of length 3 and plaintext of length 7, letters will be combined like this (ki is the key letter, pi is the plaintext letter, and ci is the resulting ciphertext letter).

prb9796.gif

The letter of the key specifies how many positions should be the plaintext letter "shifted forward" in the alphabet. If a key letter is A, the correspoding plaintext letter will be shifted by one character, B means two positions, etc. The alphabet is considered circular, so if the last letter (Z) should be shifted, it becomes A again. Please note that A (key) combined with another A (plaintext) will result in B, which may be a little unusual for the common Vigenere cipher. The Vigenere square at the end of this problem statement gives an overview how letters of a plaintext get combined with letters of a key to produce the ciphertext.

Your task is to write a program that will encrypt messages using the Vigenere cipher with a given key.

Input

Contains several instances. Each instance consists of two lines, the first line is the encryption key and the second line is the plaintext. Both key and plaintext consist of uppercase letters of the English alphabet {A, B, C, ..., Z}. The length of the key will be between 1 and 1000, the length of the plaintext between 1 and 105 inclusive.

Input is terminated by a line containing one zero.

Output

For each input instance, output the ciphertext - the encrypted version of the message.

prb9796_1.gif

Time limit 1 second
Memory limit 128 MiB
Input example #1
ICPC
THISISSECRETMESSAGE
ACM
CENTRALEUROPEPROGRAMMINGCONTEST
LONGKEY
CERC
0
Output example #1
CKYVRVIHLUUWVHIVJJU
DHAUUNMHHSRCFSEPJEBPZJQTDRAUHFU
OTFJ
Source 2011 ACM Central Europe (CERC), Prague, November 11 - 13, Problem B