Affine Cipher
InterviewTime limit5sMemory limit256 MB
Apply E(X) = (aX + b) mod 26 to each uppercase letter of the plaintext and print the ciphertext.
- Level
Easy1 of 10
- Topics
- Implementation, String, Math
- Solved
- No attempts yet
Problem
Jeongeun, trained in the western country, slipped into the eastern country. After getting hold of the eastern country's information, Jeongeun decided to use an affine cipher to send it back west safely.
An affine cipher is computed with this formula.
Map the letters A through Z to in order. With and , feeding the letter A into the formula gives , so the encrypted result is B.
Given , , and a plaintext made only of uppercase letters, write a program that turns the plaintext into ciphertext.
Input
The first line has the number of test cases ().
The first line of each test case has two integers and (). is coprime with 26.
The second line of each test case has the plaintext . Its length is greater than 0 and less than , and consists only of uppercase letters.
Output
For each test case, print the ciphertext of on its own line.