ETechSavvies

Untitled

Apr 24th, 2021 (edited)
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.55 KB | None | 0 0
  1. print('''
  2. -------------------------------------------------------------
  3. To decrypt what you encrypted ,use the negative of the shift
  4. value you entered to encrypt your message.
  5. If you used a shift value of "3" to encrypt your message,
  6. then use -3 to decrypt your message.
  7. ------------------------------------------------------------
  8. ''')
  9.  
  10. stop = 'no'
  11.  
  12. # This is our cipher function where our encryption/decryption code will be
  13. def cipher(message, shift):
  14.    
  15.     encrypted_message = ""
  16.     #we will use the ascii values starting from blankspace to "~"
  17.     #so that we can include most of the characters in our keyboard
  18.     for char in message:
  19.         if char >= " " and char <= "~":
  20.             position = ord(char) - ord(" ") #ord() will return the integer position of the character in the ascii table
  21.             position = (position + shift) % 95
  22.             new_char = chr(position + ord(" "))
  23.             encrypted_message += new_char
  24.     print("The encrypted message is: ", encrypted_message)
  25.  
  26. # This is our condition to check if a user want to continue decrypting and encrypting
  27. while stop == 'no':
  28.          
  29.         message = input("Hello there, enter the message you want to encrypt/decrypt: ")
  30.         shift = int(input("enter the shift value u want: "))
  31.  
  32.         cipher(message, shift)
  33.        
  34.         again = input("do you want to continue to encrypt/decrypt ").lower()
  35.        
  36.         if again == 'yes':
  37.             continue
  38.         else:
  39.             print("\n Thanks for using me! Till next time, Cya")
  40.             stop = 'yes'
Add Comment
Please, Sign In to add comment