Caesar Cipher

  • + 0 comments

    Here is my Python3 approach

    def caesarCipher(s, k):
        # Write your code here
        strBuild = ""
        for i in s:
            if (str.isalpha(i)):
                asc = ord(i) + k
                if (i.isupper() and asc > 90):
                    while asc > 90:
                        asc = asc - 26
                    strBuild += chr(asc)
                elif (i.islower() and asc > 122):
                    while asc > 122:
                        asc = asc - 26
                    strBuild += chr(asc)
                else:
                    strBuild += chr(asc)
            else:
                strBuild += i
            
        print(strBuild)
        return strBuild