Apply a Caesar cipher to a line of text: shift every English letter forward by k positions in the alphabet, wrapping from z back to a (and Z back to A). Uppercase stays uppercase, lowercase stays lowercase, and any character that is not a letter is left unchanged.
Line 1: the text s (printable ASCII, may contain spaces).
Line 2: a non-negative integer k.
One line: the ciphered text.
Example 1
Input
Abc-Z 2
Expected
Cde-B
Explanation
Shifting by 2: A->C, b->d, c->e, '-' unchanged, Z wraps to B, giving 'Cde-B'.
Example 2
Input
hello 0
Expected
hello
Explanation
A shift of 0 leaves the text unchanged: 'hello'.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →