Caesar Cipher

  • + 0 comments
    def caesarCipher(s, k):
        # Write your code here
        rotator = k % 26
        answer = ""
        for item in s:
            temp = item
            if item.isalpha():
                curr = ord(item) + rotator
                ascii_value = 0
                if item.isupper():
                    ascii_value = int(curr-26) if curr > ord('Z') else curr
                elif item.islower():
                    ascii_value = int(curr-26) if curr > ord('z') else curr
                temp = chr(ascii_value)
            answer += temp
        return answer