In a Caesar cipher, all characters in an input string are shifted by a number of positions. In other words, with a shift of 3 A
becomes D
, while with a shift of -2 F
becomes D
. Given an encoded string of no more than characters and the shift count (), output the decoded string.
Note that will only ever contain alphabetical characters and spaces. Also note that an containing Z
shifted by an of is perfectly valid, so you should wrap around to B
. Letter casing matters!
Input Specification
On one line, , followed by on a separate line.
Output Specification
The decoded .
Sample Input
12
Qx Bek Oazsdaa
Sample Output
El Psy Congroo
Comments
Will the entire input be on one line, always?
If you mean the text that will be decoded than yes.
Yeah I got it, thanks
Sorry, this may be dumb of me but how does Q become E? Shifting Q 12 spaces gets me to C, not E. Am I missing something here? If someone could clarify this, it would greatly be appreciated.
Although the problem is called Encode, you are actually supposed to output the decoded string. You shift to the right when you encode, so you should shift the other way when decoding.
If you guys have the time, can you reword this problem? In the beginning, I thought would result in Q wrapping around to C, and not the other way around. Thanks.
It says "Given an encoded string, output the decoded string".