1+ import sys
12def encrypt (strng , key ):
23 encrypted = ''
34 for x in strng :
@@ -20,50 +21,48 @@ def decrypt(strng, key):
2021def brute_force (strng ):
2122 key = 1
2223 decrypted = ''
23- while key != 96 :
24+ while key <= 94 :
2425 for x in strng :
2526 indx = (ord (x ) - key ) % 256
2627 if indx < 32 :
2728 indx = indx + 95
2829 decrypted = decrypted + chr (indx )
29- print (decrypted )
30+ print ("Key: {} \t | Message: {}" . format ( key , decrypted ) )
3031 decrypted = ''
3132 key += 1
3233 return None
3334
3435
3536def main ():
36- print (" **Menu**" )
37+ print ('-' * 10 + " \n **Menu**\n " + '-' * 10 )
3738 print ("1.Encrpyt" )
3839 print ("2.Decrypt" )
3940 print ("3.BruteForce" )
4041 print ("4.Quit" )
4142 while True :
42- choice = input ("what would you like to do" )
43+ choice = input ("What would you like to do?: " )
4344 if choice not in ['1' , '2' , '3' , '4' ]:
4445 print ("Invalid choice" )
4546 elif choice == '1' :
46- strng = input ("Please enter the string to be ecrypted:" )
47+ strng = input ("Please enter the string to be ecrypted: " )
4748 while True :
48- key = int (input ("Please enter off-set between 1-94" ))
49- if key > 0 and key <= 94 :
49+ key = int (input ("Please enter off-set between 1-94: " ))
50+ if key in range ( 1 , 95 ) :
5051 print (encrypt (strng , key ))
5152 main ()
5253 elif choice == '2' :
53- strng = input ("Please enter the string to be decrypted:" )
54+ strng = input ("Please enter the string to be decrypted: " )
5455 while True :
55- key = int (input ("Please enter off-set between 1-94" ))
56+ key = int (input ("Please enter off-set between 1-94: " ))
5657 if key > 0 and key <= 94 :
5758 print (decrypt (strng , key ))
5859 main ()
5960 elif choice == '3' :
60- strng = input ("Please enter the string to be decrypted:" )
61+ strng = input ("Please enter the string to be decrypted: " )
6162 brute_force (strng )
6263 main ()
6364 elif choice == '4' :
64- print ("GoodBye ." )
65- break
65+ print ("Goodbye ." )
66+ sys . exit ()
6667
6768main ()
68-
69-
0 commit comments