From c09056dd63c93c4e041a64bd6db08b33e68abd3a Mon Sep 17 00:00:00 2001 From: AMAN PANDEY <38642333+aman8423@users.noreply.github.com> Date: Thu, 4 Apr 2019 18:52:03 +0530 Subject: [PATCH] Add files via upload --- encryption1.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 encryption1.py diff --git a/encryption1.py b/encryption1.py new file mode 100644 index 0000000..375acaf --- /dev/null +++ b/encryption1.py @@ -0,0 +1,42 @@ +import random + +result = '' +choice = '' +message = '' + +characters_in_order = [chr(x) for x in range(32,127)] + +while choice != 0: + choice = input("\n Do you want to encrypt or decrypt the message?\n 1 to encrypt, 2 to decrypt or 0 to exit program. ") + + if str(choice) == '1': + message = input('\nEnter message for encryption: ') + + r_seed = input('Enter an integer to use as a seed: ') + random.seed(r_seed) + shuffled_list = [chr(x) for x in range(32,127)] + random.shuffle(shuffled_list) + + for i in range(0, len(message)): + result += shuffled_list[characters_in_order.index(message[i])] + + print(result + '\n\n') + result = '' + + elif str(choice) == '2': + message = input('\nEnter message to decrypt: ') + + r_seed = input('Enter an integer to use as a seed (should be the same one used to encrypt): ') + random.seed(r_seed) + shuffled_list = [chr(x) for x in range(32,127)] + random.shuffle(shuffled_list) + + for i in range(0, len(message)): + result += characters_in_order[shuffled_list.index(message[i])] + + print(result + '\n\n') + result = '' + + elif str(choice) != '0': + print('You have entered an invalid input, please try again. \n\n') +