Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- print('''
- -------------------------------------------------------------
- To decrypt what you encrypted ,use the negative of the shift
- value you entered to encrypt your message.
- If you used a shift value of "3" to encrypt your message,
- then use -3 to decrypt your message.
- ------------------------------------------------------------
- ''')
- stop = 'no'
- # This is our cipher function where our encryption/decryption code will be
- def cipher(message, shift):
- encrypted_message = ""
- #we will use the ascii values starting from blankspace to "~"
- #so that we can include most of the characters in our keyboard
- for char in message:
- if char >= " " and char <= "~":
- position = ord(char) - ord(" ") #ord() will return the integer position of the character in the ascii table
- position = (position + shift) % 95
- new_char = chr(position + ord(" "))
- encrypted_message += new_char
- print("The encrypted message is: ", encrypted_message)
- # This is our condition to check if a user want to continue decrypting and encrypting
- while stop == 'no':
- message = input("Hello there, enter the message you want to encrypt/decrypt: ")
- shift = int(input("enter the shift value u want: "))
- cipher(message, shift)
- again = input("do you want to continue to encrypt/decrypt ").lower()
- if again == 'yes':
- continue
- else:
- print("\n Thanks for using me! Till next time, Cya")
- stop = 'yes'
Add Comment
Please, Sign In to add comment