#K921. Caesar Cipher: Encrypt and Decrypt

    ID: 38122 Type: Default 1000ms 256MiB

Caesar Cipher: Encrypt and Decrypt

Caesar Cipher: Encrypt and Decrypt

This problem requires you to implement a Caesar Cipher with both encryption and decryption capabilities. The cipher works by shifting each alphabetical character by a specified number of positions. For encryption, each letter is shifted forward, and for decryption, it is shifted backward.

For example, given the formula for an alphabetical character \(x\) with a shift \(s\), the encrypted result is:

\(E(x) = (x + s) \mod 26\)

and the decrypted result is:

\(D(x) = (x - s) \mod 26\)

Note that the case of each letter is preserved and non-alphabetical characters remain unchanged.

inputFormat

The input is provided via standard input (stdin) and consists of three lines:

  • The first line contains a single character command: E for encryption or D for decryption.
  • The second line contains an integer representing the shift value.
  • The third line contains the text string to be processed.

Note that the shifting is performed modulo 26. For encryption, each alphabetical character is transformed using \(E(x) = (x + s) \mod 26\). For decryption, the transformation uses \(D(x) = (x - s) \mod 26\).

outputFormat

Output the resulting text after applying the Caesar cipher encryption or decryption, using standard output (stdout).

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