#K52592. Caesar Cipher Encryption and Decryption
Caesar Cipher Encryption and Decryption
Caesar Cipher Encryption and Decryption
This problem involves implementing the classic Caesar Cipher. Given an operation, a shift value, and a message, you must either encrypt or decrypt the message according to the Caesar Cipher method. In the encryption process, each letter is replaced by its counterpart shifted by a fixed number of positions in the alphabet. For decryption, the process is reversed.
For a letter c, if it is uppercase or lowercase, the cipher works as follows:
\( c' = (c - base + shift) \mod 26 + base \)
where base is \( ord('A') \) for uppercase letters and \( ord('a') \) for lowercase letters. Non-alphabetical characters remain unchanged.
inputFormat
The input will be provided through stdin in the following order, each on a new line:
- A string indicating the operation, either
ENCRYPT
orDECRYPT
. - An integer representing the shift value.
- A string representing the message. This message may include spaces, punctuation, or digits.
outputFormat
Output the encrypted or decrypted message on a single line to stdout.
## sampleENCRYPT
3
Hello, World!
Khoor, Zruog!