← Practice problem bank

Feb 4, 2026

Ciphered Communication

Daily Challenge Archive · Open

easystrings

100 pts · 2000 ms · 64 MB · Practice only

Problem

Your mission, should you choose to accept it, is to create a program that can both encrypt and decrypt messages using a Caesar cipher. This cipher is a type of substitution cipher in which each character in the plaintext is shifted a certain number of places down the alphabet. For example, with a shift of 1, 'A' would be replaced by 'B', 'B' would become 'C', etc. In addition to the message, you will be given a non-negative integer shift value. The first line of the input denotes whether you should encrypt ('E') or decrypt ('D') the provided message. All letters will be uppercase. Your program should ignore any non-alphabetical characters and spaces. Your solution will be tested against multiple test cases. Make sure your output matches exactly (including whitespace and formatting).

Hints
Consider using the ASCII values of characters to easily calculate the shifts. Be mindful of the wrapping around from 'Z' to 'A'. This is an exercise in string manipulation and modular arithmetic.

Input format

The first line of the input contains a single uppercase letter 'E' or 'D' denoting the operation (Encryption or Decryption). The second line of the input contains a non-negative integer shift value (0 ≤ shift ≤ 25). The third line of the input contains the message to be encrypted/decrypted, a string of uppercase letters (A-Z) and spaces only. (1 ≤ length of message ≤ 1000)

Output format

A single line output containing the encrypted or decrypted message. The message should be in uppercase letters with spaces intact.

Constraints

The shift will be a non-negative integer less than or equal to 25. The message will only contain uppercase letters (A-Z) and/or spaces. The length of the message will be at least 1 and at most 1000.

Sample input

'E'
1
'HELLO WORLD'

Sample output

'IFMMP XPSME'

Sign in to submit solutions

Run your code against all test cases and get instant feedback.

Sign in