#C5449. Caesar Cipher Encryption
Caesar Cipher Encryption
Caesar Cipher Encryption
You are given a string s and an integer k. Your task is to encrypt the string by shifting each alphabetical character by k positions in the alphabet. Non-alphabet characters remain unchanged.
The encryption is done using the Caesar cipher method. For an alphabetical character c, the encrypted character is computed as
$$ (c - base + k) \mod 26 + base $$
where base is the ASCII code of 'a' for lowercase letters or 'A' for uppercase letters.
For example, encrypting "abc" with a shift of 1 results in "bcd", and encrypting "XYZ" with a shift of 3 results in "ABC".
inputFormat
The first line contains an integer T
representing the number of test cases.
Each test case consists of two lines:
- The first line contains the string
s
. The string may include spaces, punctuation, and other non-alphabet characters. - The second line contains an integer
k
denoting the shift value.
The encryption formula used is: $$ (c - base + k) \mod 26 + base $$ where base
is either the ASCII code of 'a' or 'A' depending on the case of c
.
outputFormat
For each test case, output the encrypted string on a separate line. The output should be written to standard output.
## sample3
abc
1
XYZ
3
Hello, World!
5
bcd
ABC
Mjqqt, Btwqi!
</p>