#K90222. Encrypt a Message Using a Cyclic Caesar Cipher
Encrypt a Message Using a Cyclic Caesar Cipher
Encrypt a Message Using a Cyclic Caesar Cipher
You are given a lowercase alphabetic string s
and an integer k
. Your task is to encrypt the string by shifting each letter in s
by k
positions cyclically. That is, each letter c
in the string is replaced by the letter corresponding to the formula:
\( new\_index = ( (c - 'a') + k ) \mod 26 \)
The result should be printed as a single string with all letters shifted appropriately.
Examples:
- For
s = "xyz"
andk = 2
, the output iszab
. - For
s = "abc"
andk = 25
, the output iszab
. - For
s = "zzz"
andk = 2600
, the output iszzz
.
inputFormat
The input is read from standard input (stdin) and consists of two lines:
- The first line contains a string
s
consisting of lowercase letters. - The second line contains an integer
k
.
outputFormat
The output is written to standard output (stdout) and is a single line containing the encrypted string after shifting each letter by k
positions.
xyz
2
zab