Caesar Ciphers

View as PDF

Submit solution

Points: 3
Time limit: 20.0s
Memory limit: 64M

Author:
Problem type

Ryan wants to send a secret message to Malcolm. Faintly remembering a lesson on ciphers from 5th grade, Ryan decides he would make a Caesar Cipher. Wanting to find a faster way of encoding and decoding messages, Ryan decides to make a program to do it for him.


A Caesar Cipher is a simple substitution cipher; each letter of a given text is replaced by a letter some fixed number of positions down the alphabet. With a shift of 1, A would be replaced by B, B would become C, and so on.

Diagram

A positive shift would signify a shift down the alphabet (A -> B, Z -> A), a negative shift; up the alphabet (B -> A, A -> Z).

Input Specification

The first line of input will contain the integers N, the length of the string to encode, and R, the amount of shifts, seperated by a space.

The next line of input will contain the message to be encoded, a string with a length of N. All letters are guaranteed to be uppercase.

Output Specification

Output the shifted string in uppercase. Non-letter characters should not be changed.

Subtasks

Subtask 1 [0%]

1 \le N \le 10^3

-26 < R < 26

Subtask 2 [80%]

1 \le N \le 10^5

-10^5 \le R \le 10^5

Sample Input

47 7
HEY MALCOLM! WANNA HANG OUT AFTER SCHOOL TODAY?

Sample Output

OLF THSJVST! DHUUH OHUN VBA HMALY ZJOVVS AVKHF?

Explanation

A shift of 7 will look like this:

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
H I J K L M N O P Q R S T U V W X Y Z A B C D E F G

A would turn into H, B into I, etc.


Comments

There are no comments at the moment.