TCCC '25 Feb P3 - Caesar Cipher

View as PDF

Submit solution

Points: 5 (partial)
Time limit: 3.0s
Memory limit: 64M

Author:
Problem type

Caesar Ciphers are a method of encryption that was used by Julius Caesar to send messages in his private communications. The encryption is done by specifying a shift value of a message and then shifting each letter of the message by the shift value down or up the alphabet. For example, a shift value of 3 would turn an A into a D, as D is 3 letters down from A. The same can be done in reverse, a shift value of -3 would turn a D into an A. Following this process, a shift value of 2 would turn the sentence "Hello World" into "Jgnnq Yqtnf", and a shift value of -2 would turn "Jgnnq Yqtnf" into "Hello World". Given a number of sentences to encrypt or decrypt and a shift value, output each sentence correctly encrypted or decrypted using the shift value.

Input Specification

The first line of input will be an integer N (1 \le N \le 15).

The next line of input will be an integer S (-26 \le S \le 26).

The next N lines of input will have a string J (1 \le J \le 50) of letters to be encrypted or decrypted.

It is guaranteed that each string input will only have lowercase letters.

Note that letters will wrap around when shifted past the start or end of the alphabet. If given a shift value of 2 and the letter z, the shifted letter would be b. The same goes for letters when the shift value is negative. b will turn into z when given a shift value of -2.

Output Specification

Print each new sentence that was inputted, each letter of each sentence shifted accordingly with the shift value.

Sample Input

4
3
f qefkh zljmrqbo ziry fp mobqqv zlli
qeb zlkqbpqp xob crk
qeb ibpplkp xob fkqbobpqfkd
f exsb crk xq zljmrqbo ziry

Sample Output

i think computer club is pretty cool
the contests are fun
the lessons are interesting
i have fun at computer club

Sample Explanation

The number 4 is inputted, representing 4 string inputs. The number 3 is inputted, representing the shift value. The strings which are inputted then get outputted with each letter being shifted 3 letters to the right of the alphabet, and it turns out to be a decipherable message.

Sample Input 2

2
-22
this message will be encrypted
nobody will know what it says

Sample Output 2

xlmw qiwweki ampp fi irgvctxih
rsfshc ampp orsa alex mx wecw

Sample Explanation 2

The number 2 is inputted, representing 2 string inputs. The number -22 is inputted, representing the shift value. The strings which are inputted then get outputted with each letter being shifted 22 letters to the left of the alphabet, and it becomes encrypted.


Comments

There are no comments at the moment.