From 4e0184a41dd3e4838da484057d25e17234353da0 Mon Sep 17 00:00:00 2001 From: Harshil Date: Sat, 27 Oct 2018 14:14:35 +0200 Subject: [PATCH] Update caesar_cipher.py Removed unnecessary recursion and updated code! --- ciphers/caesar_cipher.py | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/ciphers/caesar_cipher.py b/ciphers/caesar_cipher.py index 6cd35e73..8012042f 100644 --- a/ciphers/caesar_cipher.py +++ b/ciphers/caesar_cipher.py @@ -34,35 +34,30 @@ def brute_force(strng): def main(): - print('-' * 10 + "\n**Menu**\n" + '-' * 10) - print("1.Encrpyt") - print("2.Decrypt") - print("3.BruteForce") - print("4.Quit") while True: + print('-' * 10 + "\n**Menu**\n" + '-' * 10) + print("1.Encrpyt") + print("2.Decrypt") + print("3.BruteForce") + print("4.Quit") choice = input("What would you like to do?: ") if choice not in ['1', '2', '3', '4']: print ("Invalid choice") elif choice == '1': strng = input("Please enter the string to be ecrypted: ") - while True: - key = int(input("Please enter off-set between 1-94: ")) - if key in range(1, 95): - print (encrypt(strng, key)) - main() + key = int(input("Please enter off-set between 1-94: ")) + if key in range(1, 95): + print (encrypt(strng.lower(), key)) elif choice == '2': strng = input("Please enter the string to be decrypted: ") - while True: - key = int(input("Please enter off-set between 1-94: ")) - if key > 0 and key <= 94: - print(decrypt(strng, key)) - main() + key = int(input("Please enter off-set between 1-94: ")) + if key > 0 and key <= 94: + print(decrypt(strng, key)) elif choice == '3': strng = input("Please enter the string to be decrypted: ") brute_force(strng) main() elif choice == '4': print ("Goodbye.") - sys.exit() - + break main()