• + 0 comments

    python3

    def caesarCipher(s, k):
        k = k % 26 
        lower = {chr(i): chr((i - ord('a') + k) % 26 + ord('a')) for i in range(ord('a'), ord('z') + 1)}
        upper = {chr(i): chr((i - ord('A') + k) % 26 + ord('A')) for i in range(ord('A'), ord('Z') + 1)}
    
        return ''.join([lower[char] if char in lower else upper[char] if char in upper else char for char in s])