This page is still under construction.

Parts of this page are still being built. What you see may change.

Simple Encryption

Time limit1sMemory limit128 MB

Summary
Remove non-letters from a message and shift each letter within its column by the alphabet position of the keyword letter above it.
Level

Easy2 of 10

Topics
String, Simulation, Implementation
Solved
No attempts yet

Problem

One of the simplest ways to encode a message is a letter shift.

For example, if you shift every letter of the original message by 55, then A becomes F in the coded message. (B →\to G, C →\to H, …, T →\to Y, U →\to Z, V →\to A, …, Z →\to E) Once you pass the end of the alphabet you wrap back around to A. To decode, simply shift back by the same amount.

A slightly trickier scheme uses a keyword to decide how far to shift. Suppose the keyword is ACT. To encode a message, first remove every non-alphabetic character, then arrange the remaining letters into a block whose width equals the keyword length. For example, take this message:

BANANA & PEEL

Written as a block with the keyword ACT as its header, it looks like this:

ACT
BAN
ANA
PEE
L

Each letter is now shifted, but the shift is not uniform — it depends on the keyword letter at the top of its column. If the column header is A, that column is not shifted; if it is B, the column shifts by 11; and so on. In this example the third column shifts by 1919, because T is the 2020th letter of the alphabet.

The encoded message is:

ACT
BCG
APT
PGX
L

Write a program that reads a keyword and a string, then encodes the string. The keyword is never longer than 66 characters, and the message is always given in uppercase.

Input

The first line contains the keyword. The second line contains the message to encode. The keyword length never exceeds 66 characters, and the total message length never exceeds 6060 characters.

Output

Output the encoded message on a single line.

Examples2

  1. Example 1

    Input
    ACT
    BANANA & PEEL
    
    Expected output
    BCGAPTPGXL
    
  2. Example 2

    Input
    TRICKY
    I LOVE PROGRAMMING!
    
    Expected output
    BCWXONKFOTKKFZVI