#K3671. Decode the Encrypted Message
Decode the Encrypted Message
Decode the Encrypted Message
You are given an encoded message s
which consists solely of lowercase English letters and spaces, and an integer n
which indicates how many positions each letter has been shifted forward (using a Caesar cipher). Your task is to decode the original message by shifting each letter backward by n
positions in the alphabet.
The decoding follows the formula:
$$ c_{decoded} = ((c - 'a' - n) \mod 26) + 'a' $$
where c
is the ASCII code of the current character. Note that spaces should remain unchanged, and if n
is larger than 26, then effectively you must use n \mod 26
since a shift of 26 leads to no change.
inputFormat
The input is read from standard input and consists of two lines:
- The first line contains an integer
n
representing the shift amount. - The second line contains the encoded message
s
, a string of lowercase letters and spaces.
outputFormat
Output the decoded message to standard output.
## sample3
khoor zruog
hello world