1
+ import sys
1
2
def encrypt (strng , key ):
2
3
encrypted = ''
3
4
for x in strng :
@@ -20,50 +21,48 @@ def decrypt(strng, key):
20
21
def brute_force (strng ):
21
22
key = 1
22
23
decrypted = ''
23
- while key != 96 :
24
+ while key <= 94 :
24
25
for x in strng :
25
26
indx = (ord (x ) - key ) % 256
26
27
if indx < 32 :
27
28
indx = indx + 95
28
29
decrypted = decrypted + chr (indx )
29
- print (decrypted )
30
+ print ("Key: {} \t | Message: {}" . format ( key , decrypted ) )
30
31
decrypted = ''
31
32
key += 1
32
33
return None
33
34
34
35
35
36
def main ():
36
- print (" **Menu**" )
37
+ print ('-' * 10 + " \n **Menu**\n " + '-' * 10 )
37
38
print ("1.Encrpyt" )
38
39
print ("2.Decrypt" )
39
40
print ("3.BruteForce" )
40
41
print ("4.Quit" )
41
42
while True :
42
- choice = input ("what would you like to do" )
43
+ choice = input ("What would you like to do?: " )
43
44
if choice not in ['1' , '2' , '3' , '4' ]:
44
45
print ("Invalid choice" )
45
46
elif choice == '1' :
46
- strng = input ("Please enter the string to be ecrypted:" )
47
+ strng = input ("Please enter the string to be ecrypted: " )
47
48
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 ) :
50
51
print (encrypt (strng , key ))
51
52
main ()
52
53
elif choice == '2' :
53
- strng = input ("Please enter the string to be decrypted:" )
54
+ strng = input ("Please enter the string to be decrypted: " )
54
55
while True :
55
- key = int (input ("Please enter off-set between 1-94" ))
56
+ key = int (input ("Please enter off-set between 1-94: " ))
56
57
if key > 0 and key <= 94 :
57
58
print (decrypt (strng , key ))
58
59
main ()
59
60
elif choice == '3' :
60
- strng = input ("Please enter the string to be decrypted:" )
61
+ strng = input ("Please enter the string to be decrypted: " )
61
62
brute_force (strng )
62
63
main ()
63
64
elif choice == '4' :
64
- print ("GoodBye ." )
65
- break
65
+ print ("Goodbye ." )
66
+ sys . exit ()
66
67
67
68
main ()
68
-
69
-
0 commit comments