small improvements!

This commit is contained in:
Harshil 2018-05-28 23:25:48 +02:00 committed by GitHub
parent f1fe458356
commit 13617225ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,3 +1,4 @@
import sys
def encrypt(strng, key): def encrypt(strng, key):
encrypted = '' encrypted = ''
for x in strng: for x in strng:
@ -20,50 +21,48 @@ def decrypt(strng, key):
def brute_force(strng): def brute_force(strng):
key = 1 key = 1
decrypted = '' decrypted = ''
while key != 96: while key <= 94:
for x in strng: for x in strng:
indx = (ord(x) - key) % 256 indx = (ord(x) - key) % 256
if indx < 32: if indx < 32:
indx = indx + 95 indx = indx + 95
decrypted = decrypted + chr(indx) decrypted = decrypted + chr(indx)
print(decrypted) print("Key: {}\t| Message: {}".format(key, decrypted))
decrypted = '' decrypted = ''
key += 1 key += 1
return None return None
def main(): def main():
print("**Menu**") print('-' * 10 + "\n**Menu**\n" + '-' * 10)
print("1.Encrpyt") print("1.Encrpyt")
print("2.Decrypt") print("2.Decrypt")
print("3.BruteForce") print("3.BruteForce")
print("4.Quit") print("4.Quit")
while True: while True:
choice = input("what would you like to do") choice = input("What would you like to do?: ")
if choice not in ['1', '2', '3', '4']: if choice not in ['1', '2', '3', '4']:
print ("Invalid choice") print ("Invalid choice")
elif choice == '1': elif choice == '1':
strng = input("Please enter the string to be ecrypted:") strng = input("Please enter the string to be ecrypted: ")
while True: while True:
key = int(input("Please enter off-set between 1-94")) key = int(input("Please enter off-set between 1-94: "))
if key > 0 and key <= 94: if key in range(1, 95):
print (encrypt(strng, key)) print (encrypt(strng, key))
main() main()
elif choice == '2': elif choice == '2':
strng = input("Please enter the string to be decrypted:") strng = input("Please enter the string to be decrypted: ")
while True: while True:
key = int(input("Please enter off-set between 1-94")) key = int(input("Please enter off-set between 1-94: "))
if key > 0 and key <= 94: if key > 0 and key <= 94:
print(decrypt(strng, key)) print(decrypt(strng, key))
main() main()
elif choice == '3': elif choice == '3':
strng = input("Please enter the string to be decrypted:") strng = input("Please enter the string to be decrypted: ")
brute_force(strng) brute_force(strng)
main() main()
elif choice == '4': elif choice == '4':
print ("GoodBye.") print ("Goodbye.")
break sys.exit()
main() main()