#P1079. Vigenère Cipher Encryption

    ID: 12829 Type: Default 1000ms 256MiB

Vigenère Cipher Encryption

Vigenère Cipher Encryption

The Vigenère cipher is a method of encrypting alphabetic text by using a series of interwoven Caesar ciphers based on the letters of a keyword. In this problem, you are given a plaintext string M and a key string k. The encryption is performed by aligning the plaintext with a repeated key and shifting each letter according to the corresponding key character.

For each character mi in the plaintext and the corresponding key character kj (where the key is repeated if necessary), the ciphertext character ci is computed as follows:

$$c_i = m_i \oplus k_j \quad, \quad \text{where } \oplus \text{ is defined over the alphabet as follows} $$

The operation \(\oplus\) is performed by converting both letters to uppercase (or lowercase) for the arithmetic (with \(A=0, B=1, \ldots, Z=25\)), then shifting the plaintext letter by the key letter's offset, and finally preserving the original case of the plaintext letter in the ciphertext.

For example, if the plaintext is Helloworld and the key is abc, then the encryption produces Hfnlpyosnd as shown below:

PlaintextHelloworld
Keyabcabcabca
CiphertextHfnlpyosnd

Note that the case of the letters in the plaintext is preserved while the key letters (irrespective of their case) determine the shift.

inputFormat

The input consists of two lines. The first line contains the plaintext string M. The second line contains the key string k. Both strings contain only alphabetic characters.

outputFormat

Output the ciphertext resulting from applying the Vigenère cipher encryption to the plaintext using the given key. The letter case in the plaintext should be preserved.

sample

Helloworld
abc
Hfnlpyosnd