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
    function.
  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:
https://www.tutorialspoint.com/cryptography_with_python/cryptography_
with_python_caesar_cipher.htm

A Python implementation of the Caesar cipher:
https://www.geeksforgeeks.org/caesar-cipher-in-python/

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