Caesar cipher

Shift every letter of a line k places forward in the alphabet, wrapping round from z to a (and Z to A). Keep the case, and leave other characters unchanged. This is the Caesar cipher.

Input

The first line has k (0 ≤ k ≤ 25). The second line has the text (up to 200 characters).

Output

The shifted text.

Examples

Example 1 · Input
3
Hello, World!
Expected output
Khoor, Zruog!
Example 2 · Input
1
xyz
Expected output
yza

Hints

Hint 1

For a lowercase letter c: 'a' + (c - 'a' + k) % 26.

Hint 2

Uppercase letters work the same way with 'A'; other characters stay as they are.

Hint 3

Read the whole line with fgets.

Solution

Show one correct solution (try it yourself first)
#include <stdio.h>

int main(void) {
    int k;
    char line[256];
    scanf("%d ", &k);
    fgets(line, sizeof line, stdin);
    for (int i = 0; line[i] != '\0'; i++) {
        char c = line[i];
        if (c >= 'a' && c <= 'z') c = 'a' + (c - 'a' + k) % 26;
        else if (c >= 'A' && c <= 'Z') c = 'A' + (c - 'A' + k) % 26;
        putchar(c);
    }
    return 0;
}

Lesson: Characters and text →