Simple Encryption
Time limit1sMemory limit128 MB
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 , then A becomes F in the coded message. (B G, C H, …, T Y, U Z, V A, …, Z 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:
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 ; and so on. In this example the third column shifts by , because T is the th letter of the alphabet.
The encoded message is:
Write a program that reads a keyword and a string, then encodes the string. The keyword is never longer than 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 characters, and the total message length never exceeds characters.
Output
Output the encoded message on a single line.