#K66132. Rotate String Encryption
Rotate String Encryption
Rotate String Encryption
You are given a string s
consisting of lowercase English letters and an integer k
(with \(0 \le k \le 25\)). Your task is to rotate each character in s
by k
positions in the English alphabet. The rotation should wrap around, that is, after 'z' comes 'a'.
The transformation of a character \(c\) can be mathematically represented as:
\( c' = ((c - 'a' + k) \mod 26) + 'a' \)
You need to process multiple test cases. For each test case, you are given an integer k
and a string s
, and you must output the rotated (encrypted) string.
Example:
Input: 2 3 abc 1 xyz Output: def yza
inputFormat
The first line contains a single integer T
which denotes the number of test cases. Each of the following T
lines contains a test case with an integer k
and a string s
separated by space.
Constraints:
- \(0 \le k \le 25\)
s
consists only of lowercase English letters.- \(1 \leq |s| \leq 10^6\)
outputFormat
For each test case, output the encrypted string obtained after rotating each character by k
positions. Each result should be printed on a new line.
2
3 abc
1 xyz
def
yza
</p>