Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Simple Data Encryption

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

Your question is Simple Data Encryption. 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

Write a function to implement a simple data encryption algorithm.

Implement a Caesar cipher that shifts each English letter by shift positions, wrapping around the alphabet. Preserve uppercase and lowercase characters, leave digits and punctuation unchanged, and support negative or large shifts.

Function

def encrypt(text, shift):

Return the encrypted string.

Constraints

  • 0 <= len(text) <= 1000
  • text contains arbitrary Unicode characters, but only English letters A-Z and a-z are shifted
  • shift is an integer
  • Digits, whitespace, punctuation, and non-English characters remain unchanged

Function Signature

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