Caesar Cipher

  • + 0 comments
    def cypher(k):
            def mapper(c):
                    if not c.isalpha():
                            return c
                    n_letters = 26
                    a = ord('A') if c.isupper() else ord('a')
                    c = ord(c)
                    new_c = ((c - a + k) % n_letters) + a
                    return chr(new_c)
    return mapper
    
    def caesarCipher(s, k):
        return "".join(map(cypher(k), [x for x in s]))
    

    k): # Write your code here return "".join(map(cypher(k), [x for x in s])