#K51277. Caesar Cipher Encoding

    ID: 29052 Type: Default 1000ms 256MiB

Caesar Cipher Encoding

Caesar Cipher Encoding

In this problem, you are given a string message and an integer shift. Your task is to encode the message using the Caesar cipher technique. In a Caesar cipher, each letter in the plain text is shifted by a fixed number of positions in the alphabet. Formally, for a letter c, its encoded value is given by

[ c' = \begin{cases} \text{chr}((\text{ord}(c) - \text{ord}('a') + shift) \mod 26 + \text{ord}('a')) & \text{if } c \text{ is a lowercase letter},\[6pt] \text{chr}((\text{ord}(c) - \text{ord}('A') + shift) \mod 26 + \text{ord}('A')) & \text{if } c \text{ is an uppercase letter},\[6pt] c & \text{otherwise.} \end{cases} ]

Other characters (such as punctuation, digits, and spaces) remain unchanged. The encoding wraps around the alphabet; for example, shifting 'z' by 1 returns 'a'.

inputFormat

The input is read from standard input (stdin) and consists of two lines. The first line contains the message string. The second line contains an integer representing the shift value.

outputFormat

Output the encoded message as a single line to standard output (stdout).## sample

abc
1
bcd