Caesar Cipher

  • + 0 comments

    Python 3:

    def caesarCipher(s: str, k: int) -> str:
        k = k % 26
        rotated = ascii_lowercase[k:] + ascii_lowercase[:k]
        return s.translate(
            str.maketrans(
                dict(zip(ascii_letters, f"{rotated}{rotated.upper()}", strict=True))
            )
        )