Undo a Caesar cipher

A free easy coding practice problem from security. Solve it in JavaScript, TypeScript or Python and check your solution against fresh hidden tests — edge cases and random inputs — as often as you like.

Difficulty
Easy
Type
Function
Topic
Security
Languages
JavaScript, TypeScript or Python

Problem

text was encrypted by shifting every letter FORWARD by shift positions in the alphabet (wrapping z → a). Return the decrypted text: shift every letter back by shift, keeping its case (uppercase stays uppercase). Characters that are not ASCII letters (digits, spaces, punctuation) are unchanged. 0 ≤ shift ≤ 1000; text is printable ASCII of at most 500 characters.

Function signature

// JavaScript
function caesarDecode(text, shift)

// TypeScript
function caesarDecode(text: any, shift: any): any

// Python
def caesar_decode(text, shift):

Examples

  1. caesarDecode("Khoor, Zruog!", 3) → "Hello, World!"
  2. caesarDecode("bcd xyz", 27) → "abc wxy"
  3. caesarDecode("ABC", 0) → "ABC"

How checking works

Run your code against the examples above, then submit a check: it runs on the server against hidden tests built fresh each time, including edge cases and random inputs. Practice is untimed and never affects a verified score; when you are ready, take a graded coding challenge to earn a badge.

More practice problems

Next steps