From f293563ec760358c24f74985953a42fe3b6f3802 Mon Sep 17 00:00:00 2001 From: XChaosSaMa Date: Thu, 7 Nov 2024 13:06:39 -0500 Subject: [PATCH] completed cipher --- cipher.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/cipher.py b/cipher.py index 0e772db..1c11ad0 100644 --- a/cipher.py +++ b/cipher.py @@ -1 +1,15 @@ -# add your code here +def caesar_cipher(text, shift): + encrypted_text = "" + for char in text: + if char.isalpha(): + shift_base = 65 if char.isupper() else 97 + encrypted_text += chr((ord(char) - shift_base + shift) % 26 + shift_base) + else: + encrypted_text += char + return encrypted_text + + +user_input = input("Please enter a sentence: ") +shift = 5 +result = caesar_cipher(user_input, shift) +print("The encrypted sentence is:", result)