#C3913. Caesar Cipher

    ID: 47393 Type: Default 1000ms 256MiB

Caesar Cipher

Caesar Cipher

This problem requires you to implement a Caesar cipher algorithm. Given a message, an integer shift, and a direction ('left' or 'right'), you need to shift the letters of the message accordingly. The cipher works as follows: for each alphabetical character, its new position is determined by the formula \( new = (old + shift) \mod 26 \). Non-alphabet characters remain unchanged.

Note: A right shift moves a letter forward in the alphabet, whereas a left shift moves it backward. The shift value may be larger than 26; in such cases, it should be normalized by taking its modulo with 26.

inputFormat

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

  1. A string representing the message.
  2. An integer representing the shift amount.
  3. A string (either 'left' or 'right') indicating the direction of the shift.

outputFormat

Output the encoded message to standard output (stdout).## sample

abc
1
right
bcd