#C658. Caesar Cipher Encryption
Caesar Cipher Encryption
Caesar Cipher Encryption
You are given an uppercase string s
and an integer k
. Your task is to encrypt the string using the Caesar Cipher technique.
In a Caesar Cipher, each letter in the string is shifted by k
positions in the alphabet. More formally, each letter c
is replaced by a new letter given by the formula:
$$ new\_char = \texttt{chr}(((\texttt{ord}(c) - \texttt{ord}('A') + k) \mod 26) + \texttt{ord}('A')) $$
The alphabet is considered cyclic, so letters that go past 'Z' wrap around back to 'A'.
For example, if s = "HELLO"
and k = 3
, the encrypted string is "KHOOR".
inputFormat
The input consists of two lines:
- The first line contains a string
s
consisting of uppercase English letters. - The second line contains an integer
k
which represents the shift for the cipher.
outputFormat
Output the encrypted string after applying the Caesar Cipher with the given shift.
## sampleHELLO
3
KHOOR