Caesar Cipher
InterviewTime limit1sMemory limit128 MB
Given the encrypted message and its original first letter, recover the shift and decode the full message.
- Level
Easy1 of 10
- Topics
- String, Implementation
- Solved
- No attempts yet
Problem
Hektor recently learned about a message-encryption method called the "Caesar cipher". It is based on the positions that individual letters occupy in the alphabet. In this problem we use the standard 26-letter English alphabet:
a b c d e f g h i j k l m n o p q r s t u v w x y z
To encrypt a message with the Caesar cipher, first choose an integer from 0 to 25 (choosing 0 makes the encryption completely ineffective), which we call K. Then replace every letter of the message with the letter that sits K positions later in the alphabet. If the letter K positions later goes past the end of the alphabet, treat the alphabet as repeating forever, so right after 'z' comes 'a' again, then 'b', and so on.
For example, with K = 2 the message "zoska" is encrypted as "bqumc".
Hektor sent Wiktor a message encrypted with the Caesar cipher, but did not reveal the value of K he used. Instead, together with the message he told Wiktor which letter the original message started with before encryption. Is that information enough to decrypt the message?
Write a program that, given the first letter of the original message and its encrypted version, decrypts the message.
Input
The first line contains a natural number Z (1 ≤ Z ≤ 10), the number of test cases. The test cases follow, each described by three lines.
The first line of a test case contains a natural number N (1 ≤ N ≤ 1000000), the number of letters in the encrypted message.
The second line contains the N lowercase English letters that make up the encrypted message.
The third line contains a single lowercase English letter, the first letter of the original message.
Output
For each test case, print the decrypted message on its own line.