Exercise: implementing a Caesar cipher in Python

Implement the function caesar_encrypt(plaintext: str, shift: int) -> str that
takes a string plaintext and an integer shift as input, and returns the Caesar-
encrypted version of the input string.

To implement the Caesar cipher, you will need to do the following:

  1. Iterate through each character in the input string.
  2. Convert the character to its ASCII code using the ord function.
  3. Shift the ASCII code by the specified number of positions using addition.
  4. Convert the shifted ASCII code back to a character using the chr
  5. Repeat these steps for each character in the input string, and return the
    resulting encrypted string.

Blog Reference:

A tutorial on the Caesar cipher:

A Python implementation of the Caesar cipher:

Open chat
Hello 👋.
Tell me, how can I help you?