• + 0 comments
    def caesarCipher(s, k):
        # Write your code here
        new_string = ""
        for char in s:
            if char.isalpha():
                min_limit = ord("a") if char.islower() else ord("A")
                max_limit = ord("z") if char.islower() else ord("Z")
                pos = ord(char) + (k % 26)
    
                if min_limit <= pos <= max_limit:
                    new_string += chr(pos)
                elif pos > max_limit:
                    new_string += chr((pos - max_limit) + (min_limit - 1))
            else:
                new_string += char
    
        return new_string