From beae52df304c9d510e11911716bd6f51ecc31a43 Mon Sep 17 00:00:00 2001 From: KennedyAjana <150489668+KennedyAjana@users.noreply.github.com> Date: Fri, 15 Nov 2024 12:01:07 -0500 Subject: [PATCH 1/2] Update cipher.py Added my code --- cipher.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/cipher.py b/cipher.py index 0e772db..30b09b4 100644 --- a/cipher.py +++ b/cipher.py @@ -1 +1,27 @@ -# add your code here +# def caesar_cipher_encrypt(text, shift): + +text = alphabet(alpha) +shift = int(input("Please enter the number of places to shift:")) +plain text = input("Please enter a sentence:") +plain_text = plain text.ord('A') if char.isupper() else ord('a') + +encrypted_text = "" + +for char in plain_text: + if char.isalpha(): # Check if the character is a letter + index = alpha.find(char) + index = (index + shift) % 26 + char = alpha(index) + + else: + # Keep special characters unchanged + encrypted_text += char + return encrypted_text + +# Ask the user for a plain text sentence +plain_text = input("Enter the text to be encrypted: ") +shift = 5 # Right shift of 5 + +# Encrypt the text +encrypted_text = caesar_cipher_encrypt(plain_text, shift) +print("Encrypted text:", encrypted_text) From 83c3cccc7028774e1c8aaf600a3a7e6b08c6cb21 Mon Sep 17 00:00:00 2001 From: KennedyAjana <150489668+KennedyAjana@users.noreply.github.com> Date: Wed, 20 Nov 2024 00:44:44 -0500 Subject: [PATCH 2/2] Update cipher.py Revised code --- cipher.py | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/cipher.py b/cipher.py index 30b09b4..b82ffa0 100644 --- a/cipher.py +++ b/cipher.py @@ -1,27 +1,15 @@ -# def caesar_cipher_encrypt(text, shift): +alphabet = "abcdefghijklmnopqrstuvwxyz" -text = alphabet(alpha) -shift = int(input("Please enter the number of places to shift:")) -plain text = input("Please enter a sentence:") -plain_text = plain text.ord('A') if char.isupper() else ord('a') +shift = int(input("Please enter number of places to shift:")) +plain_text= input("Please enter a sentence: ") encrypted_text = "" for char in plain_text: - if char.isalpha(): # Check if the character is a letter - index = alpha.find(char) + if char in alphabet: + index = alphabet.find(char) index = (index + shift) % 26 - char = alpha(index) - - else: - # Keep special characters unchanged - encrypted_text += char - return encrypted_text + char = alphabet[index] + encrypted_text += char -# Ask the user for a plain text sentence -plain_text = input("Enter the text to be encrypted: ") -shift = 5 # Right shift of 5 - -# Encrypt the text -encrypted_text = caesar_cipher_encrypt(plain_text, shift) -print("Encrypted text:", encrypted_text) +print(encrypted_text)