#K49462. Rotational Cipher Problem

    ID: 28648 Type: Default 1000ms 256MiB

Rotational Cipher Problem

Rotational Cipher Problem

You are given a string text and an integer shift. Your task is to encrypt the text using a rotational (Caesar) cipher and output the encrypted text. In this cipher, each letter is replaced by a letter some fixed number of positions down the alphabet. The encryption should preserve the case of the letters and leave all non-alphabetical characters unchanged.

The transformation for each letter c is defined as follows:

[ E(c) = \begin{cases} \text{chr}(((\text{ord}(c) - \text{ord}(\text{base}) + shift) \mod 26) + \text{ord}(\text{base})) & \text{if } c \text{ is a letter} \ c & \text{otherwise} \end{cases} ]

where base is 'A' for uppercase letters and 'a' for lowercase letters.

Example:

Input:
Apply Rotation
3

Output: Dssob Wrdwfwlrq

</p>

inputFormat

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

  • The first line is a string text which may contain spaces and punctuation.
  • The second line is an integer shift representing the number of positions by which each alphabetical character should be shifted.

outputFormat

Output the encrypted text to stdout as a single line string.

## sample
Apply Rotation
3
Dssob Wrdwfwlrq