Skip to content

Commit 4e0184a

Browse files
authored
Update caesar_cipher.py
Removed unnecessary recursion and updated code!
1 parent a84f7c0 commit 4e0184a

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

ciphers/caesar_cipher.py

+12-17
Original file line numberDiff line numberDiff line change
@@ -34,35 +34,30 @@ def brute_force(strng):
3434

3535

3636
def main():
37-
print('-' * 10 + "\n**Menu**\n" + '-' * 10)
38-
print("1.Encrpyt")
39-
print("2.Decrypt")
40-
print("3.BruteForce")
41-
print("4.Quit")
4237
while True:
38+
print('-' * 10 + "\n**Menu**\n" + '-' * 10)
39+
print("1.Encrpyt")
40+
print("2.Decrypt")
41+
print("3.BruteForce")
42+
print("4.Quit")
4343
choice = input("What would you like to do?: ")
4444
if choice not in ['1', '2', '3', '4']:
4545
print ("Invalid choice")
4646
elif choice == '1':
4747
strng = input("Please enter the string to be ecrypted: ")
48-
while True:
49-
key = int(input("Please enter off-set between 1-94: "))
50-
if key in range(1, 95):
51-
print (encrypt(strng, key))
52-
main()
48+
key = int(input("Please enter off-set between 1-94: "))
49+
if key in range(1, 95):
50+
print (encrypt(strng.lower(), key))
5351
elif choice == '2':
5452
strng = input("Please enter the string to be decrypted: ")
55-
while True:
56-
key = int(input("Please enter off-set between 1-94: "))
57-
if key > 0 and key <= 94:
58-
print(decrypt(strng, key))
59-
main()
53+
key = int(input("Please enter off-set between 1-94: "))
54+
if key > 0 and key <= 94:
55+
print(decrypt(strng, key))
6056
elif choice == '3':
6157
strng = input("Please enter the string to be decrypted: ")
6258
brute_force(strng)
6359
main()
6460
elif choice == '4':
6561
print ("Goodbye.")
66-
sys.exit()
67-
62+
break
6863
main()

0 commit comments

Comments
 (0)