#C4100. Caesar Cipher: Encode and Decode

    ID: 47602 Type: Default 1000ms 256MiB

Caesar Cipher: Encode and Decode

Caesar Cipher: Encode and Decode

This problem requires you to implement a variant of the Caesar Cipher. The Caesar Cipher is a simple substitution cipher where each letter in the plaintext is replaced by a letter some fixed number of positions down the alphabet.

Given a string text, an integer shift, and a choice ('encode' or 'decode'), you are to encode or decode the text accordingly. The transformation for a letter p is defined as:

\( c = (p + s) \mod 26 \)

for encoding, and

\( c = (p - s) \mod 26 \)

for decoding, where s is the shift value. Non-alphabetical characters should remain unchanged.

inputFormat

The input is given via stdin and consists of three lines:

  • The first line is the text (a string) to be processed.
  • The second line is an integer representing the shift value.
  • The third line is a string which is either encode or decode indicating the operation.

outputFormat

Output a single line via stdout containing the resulting text after applying the Caesar Cipher transformation.

## sample
Hello, World!
3
encode
Khoor, Zruog!