Advertisement
uottawamakermobile

Encrypt, Decrypt (Complete)

Apr 7th, 2020
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.86 KB | None | 0 0
  1.  
  2. #Function that encrypts a sentence
  3. def encrypt(sentence):
  4.     result = []
  5.  
  6.     #Encryption algorithm = ASCII value -200
  7.     for letter in sentence:
  8.         l = ord(letter)-200
  9.         result.append(l)
  10.  
  11.     print("This is your encrypted message!")
  12.  
  13.     #print encrypted value
  14.     for numbers in result:
  15.         print(numbers,end='') #'end=' enables numbers to be printed on same line
  16.         print(" ",end='')
  17.  
  18.     print() #leave one line    
  19.     decrypt(result)
  20.  
  21. #function that decrypts a sentence
  22. def decrypt(result):
  23.     end_string = ""
  24.  
  25.     for numbers in result:
  26.         l = int(numbers) #convert characters in l into integer
  27.         l = l + 200
  28.         l = chr(l)
  29.         end_string = end_string + l
  30.  
  31.     print("Your decrypted message is:")
  32.     print(end_string)
  33.  
  34. s = input("Input a message you would like to encrypt: ")
  35. encrypt(s)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement