easy +10 pts

Caesar Cipher Decrypt

Decode a message shifted by a given number of letters in the alphabet.

Write a function `caesar_decrypt(text: str, shift: int) -> str` that takes a string `text` and an integer `shift`. Each lowercase letter ('a'-'z') should be shifted back by `shift` positions in the alphabet, wrapping around. Uppercase letters ('A'-'Z') should be shifted back similarly. All other characters (digits, spaces, punctuation, etc.) must remain unchanged. The `shift` is guaranteed to be a non-negative integer. For example, with `shift=3`, 'd' becomes 'a', 'C' becomes 'Z'.

Constraints

- `0 <= shift <= 10^9` - `0 <= len(text) <= 10^5` - The implementation should be O(n) time and O(n) space.

Example

>>> caesar_decrypt('khoor', 3)
'hello'
>>> caesar_decrypt('WKH TXLFN EURZQ IRA', 3)
'THE QUICK BROWN FOX'
>>> caesar_decrypt('abc', 0)
'abc'
>>> caesar_decrypt('abc', 28)
'yza'
10 points ~15 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Use `ord()` and `chr()` to convert between characters and ASCII values.
Remember to handle wrapping: subtract shift and add 26 if the result goes below 'a' or 'A'.
Use `shift % 26` to handle large shifts efficiently.
Build the result as a list of characters and join at the end.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.