From 4df43673da8cc97a3d88a6ce7c06d8f203b265d0 Mon Sep 17 00:00:00 2001 From: Whitney Parks Date: Thu, 21 Nov 2024 14:30:19 -0500 Subject: [PATCH] updated caesar cipher --- cipher.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/cipher.py b/cipher.py index 0e772db..b71f61a 100644 --- a/cipher.py +++ b/cipher.py @@ -1 +1,14 @@ -# add your code here +def caesar_cipher(text, shift): + result = "" + for char in text: + if char.isalpha(): + shift_amount = 65 if char.isupper() else 97 + result += chr((ord(char) - shift_amount + shift) % 26 + shift_amount) + else: + result += char + return result + +text = "python is fun!" +shift = 5 +encrypted_text = caesar_cipher(text, shift) +print("Encrypted text:", encrypted_text)