#C12269. Caesar Cipher

    ID: 41677 Type: Default 1000ms 256MiB

Caesar Cipher

Caesar Cipher

Given a string S and an integer K, shift each alphabetic character in S by K positions in the alphabet. The shift should preserve the case for uppercase and lowercase letters. If the shift passes the end of the alphabet, wrap around to the beginning. Non-alphabetic characters should remain unchanged.

The transformation follows the formula:

\( new\_char = (char - base + K) \mod 26 + base \)

where base is \( ord('A') \) for uppercase letters and \( ord('a') \) for lowercase letters.

For example:

  • Input: "Hello, World!" and 5 → Output: "Mjqqt, Btwqi!"
  • Input: "xyzXYZ" and 3 → Output: "abcABC"
  • Input: "Mjqqt, Btwqi!" and -5 → Output: "Hello, World!"

inputFormat

The input consists of two lines:

  1. The first line contains the string S.
  2. The second line contains an integer K, which represents the shift value.

outputFormat

Output the transformed string after applying the Caesar cipher shift.

## sample
Hello, World!
5
Mjqqt, Btwqi!