Caesar Cipher - aloalgo

Caesar Cipher

Medium

Implement the Caesar cipher, a simple and widely known encryption technique. It is a type of substitution cipher in which each letter in the plaintext is replaced by a letter some fixed number of positions down the alphabet. The input string will consist of lowercase English letters only.

Example 1

Inputs
s = "abc"
shift = 3
Output
"def"
Explanation:

Each letter is shifted 3 positions forward: 'a' -> 'd', 'b' -> 'e', 'c' -> 'f'.

Example 2

Inputs
s = "xyz"
shift = 3
Output
"abc"
Explanation:

'x' shifted 3 becomes 'a' (wraps around), 'y' becomes 'b', 'z' becomes 'c'.

Example 3

Inputs
s = "def"
shift = -3
Output
"abc"
Explanation:

Each letter is shifted 3 positions backward: 'd' -> 'a', 'e' -> 'b', 'f' -> 'c'.

Loading...
Inputs
s = "abc"
shift = 3
Output
"def"

Hello! I am your ✨ AI assistant. I can provide you hints, explanations, give feedback on your code, and more. Just ask me anything related to the problem you're working on!