O05

Caesar Shift Cipher

Mid / Senior Engineer
Target Time: 25 - 35 Minutes
Type: STRING

Problem Statement & Objective

Implement a Caesar cipher encoder that shifts every English alphabetical character forward by k positions in the alphabet. Uppercase letters wrap around to uppercase letters, and lowercase letters wrap around to lowercase letters. Non-alphabetic characters (digits, spaces, punctuation) remain unchanged.

Function Signature (Python)

crack_caesar_cipher(ciphertext: str, dictionary: list[str]) -> str

Input & Output Contract

Output Rule:Shifted encoded string. Case is preserved. Non-letters unchanged.

System Constraints

0 <= metin.length <= 10^5
0 <= k <= 10^9

Example Execution Walkthrough

metin = "Hello, World!", k = 3
'H' -> 'K', 'e' -> 'h', 'l' -> 'o', ...
result: "Khoor, Zruog!"

Example Test Scenarios (3)

Example 1
Input:["khoor zruog",["hello","world","foo","bar"]]
Expected Output:"hello world"
Example 2: 1 Karakter Kaydırma
Input:["bc",["ab","cd"]]
Expected Output:"ab"
Example 3: 0 Kaydırma (Doğrudan Eşleşme)
Input:["apple",["apple"]]
Expected Output:"apple"
Loading Python Editor...
Input Parameters
[
  "khoor zruog",
  [
    "hello",
    "world",
    "foo",
    "bar"
  ]
]
Expected Output
"hello world"