#K91797. Caesar Cipher Transformation
Caesar Cipher Transformation
Caesar Cipher Transformation
You are given a string S and an integer n. Your task is to transform the string by shifting each alphabetical character by n positions in the alphabet. Characters that are not letters should remain unchanged.
The transformation is defined by the following formula for any alphabetical character c:
$$\text{new}(c) = \begin{cases} \text{chr}(((\text{ord}(c) - \text{ord}(\text{base}) + n) \bmod 26) + \text{ord}(\text{base})) & \text{if } c \text{ is a letter},\\ c & \text{otherwise}, \end{cases} $$where \(\text{base}\) is \(\text{ord}('a')\) for lowercase letters and \(\text{ord}('A')\) for uppercase letters.
Read the input from standard input and output the transformed strings, each on a new line.
inputFormat
The first line of input contains a single integer T denoting the number of test cases.
The description of each test case follows:
- A line containing the string S (which may include spaces and punctuation).
- A line containing an integer n representing the shift value.
Note that \(0 \leq n \leq 10^9\) is allowed, and the shifting operation should use modulo 26 arithmetic.
outputFormat
For each test case, output a single line containing the transformed string after applying the Caesar Cipher shift.
## sample3
abc
1
XYZ
3
Hello, World!
5
bcd
ABC
Mjqqt, Btwqi!
</p>