#C5987. Caesar Cipher Encryption
Caesar Cipher Encryption
Caesar Cipher Encryption
This problem requires you to implement the caesarCipher
function which encrypts a given text using the Caesar cipher technique. The encryption works by shifting each letter in the text by a fixed number of positions in the alphabet. Specifically, if a letter is shifted past 'Z' or 'z', it wraps back around to the beginning of the alphabet. Mathematically, for a letter with an initial position \( x \) (where \( x \) is its 0-indexed alphabetic position), the new letter's position is given by:
\( (x + shift) \mod 26 \)
The function must handle both positive and negative shift values as well as leave non-alphabetic characters unchanged.
inputFormat
The input consists of two lines:
- The first line contains a string
text
to be encrypted. This string may include spaces, punctuation, and other symbols. - The second line contains an integer
shift
which specifies the number of positions each letter should be shifted.
outputFormat
The output should be a single line containing the encrypted text produced by applying the Caesar cipher to the input string using the given shift value.
## sampleHello, World!
3
Khoor, Zruog!