#K92542. Alphabet Shift Cipher
Alphabet Shift Cipher
Alphabet Shift Cipher
You are given a string message
and an integer n
. Your task is to shift each alphabetical character in the string by n
positions in the alphabet. The shifting should wrap around the alphabet; that is, after 'z' comes 'a' and after 'Z' comes 'A'. Non-alphabetical characters (such as punctuation, spaces, digits, etc.) should remain unchanged. Both uppercase and lowercase letters must be handled appropriately.
For example, when shifting "abc" by 2, the result is "cde"; when shifting "XYZ" by 1, the result is "YZA".
Note: The shifting should follow the Caesar cipher technique.
inputFormat
The input consists of two lines:
- The first line contains a non-empty string
message
that may include spaces and punctuation. - The second line contains a single integer
n
representing the shift amount.
Please read the input from stdin
.
outputFormat
Output a single line which is the resulting string after shifting the letters in message
by n
positions. Write your answer to stdout
.
abc
2
cde