Text processing · 11 / 14 Exercise Medium

Caesar cipher

Objective

Create a Python program that encrypts a text with the Caesar cipher, which shifts each letter a fixed number of positions in the alphabet.

Instructions

  • Read the shift, an integer (it can be negative), and then the text.
  • Shift each letter of the English alphabet (from a to z) by the given number of positions, going back to the start when it goes past z. Keep whether the letter was upper or lower case.
  • All other characters (spaces, numbers and signs) are left unchanged.
  • Show the encrypted text. ord, chr and the % operator will be useful.
Input
3
Hola Mundo
Output
Krod Pxqgr

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise