#C621. Caesar Cipher Shift
Caesar Cipher Shift
Caesar Cipher Shift
In this problem, you are given a message and an integer shift. Your task is to encode the message using the Caesar Cipher technique. For each alphabetic character in the message, shift it by shift positions in the alphabet. The shift is cyclic (wrap around once the end of the alphabet is reached) and should preserve the case. Non-alphabetic characters remain unchanged.
The encryption for a letter \(x\) is given by the formula: \(E(x) = (x + \text{shift}) \mod 26\), where \(x\) is the 0-indexed position of the letter in the alphabet.
Read the input from standard input (stdin
) and output the encoded message to standard output (stdout
).
inputFormat
The input consists of two lines:
- The first line is a string
message
which may contain spaces and punctuation. - The second line is an integer
shift
indicating the number of positions each alphabet character should be shifted.
outputFormat
Output a single line containing the encoded message after applying the Caesar Cipher.
## sampleHello, World!
3
Khoor, Zruog!