Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Implement Caesar Cipher Shift 4

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Implement Caesar Cipher Shift 4. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Implement a Caesar cipher encryption that shifts each letter by 4 positions (e.g., A->E, V->Z, W->A). Preserve uppercase and lowercase characters, and leave digits, spaces, punctuation, and other non-letter characters unchanged. Implement def caesar_cipher(text):, accepting a string and returning the encrypted string. For example, "Attack at Dawn!" returns "Exxego ex Hear!", and "XYZ xyz" returns "BCD bcd".

Constraints

  • 0 <= len(text) <= 10^5
  • text contains standard ASCII characters
  • The shift is always exactly 4 positions
  • Uppercase and lowercase letters must retain their case
  • Non-letter characters must remain unchanged

Function Signature

def caesar_cipher(text):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output