Advertisement
Guest User

Untitled

a guest
Jan 21st, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. #1
  2. key = 7
  3. message = "Hello"
  4. def encrypt(message, key):
  5. message = message.lower()
  6. secret = ""
  7. for c in message:
  8. if c in "abcdefghijklmnopqrstuvwxyz":
  9. num = ord(c)
  10. num += key
  11. if num > ord("z"):
  12. num -= 26
  13. elif num < ord("a"):
  14. num += 26
  15. secret = secret + chr(num)
  16. else:
  17. # don't modify any non-letters in the message; just add them as-is
  18. secret = secret + c
  19. return secret
  20.  
  21.  
  22. #2
  23.  
  24. key = -7
  25. message = "Hello"
  26. def decrypt(message, key):
  27. message = message.lower()
  28. secret = ""
  29. for c in message:
  30. if c in "abcdefghijklmnopqrstuvwxyz":
  31. num = ord(c)
  32. num += key
  33. if num > ord("z"):
  34. num -= 26
  35. elif num < ord("a"):
  36. num += 26
  37. secret = secret + chr(num)
  38. else:
  39. # don't modify any non-letters in the message; just add them as-is
  40. secret = secret + c
  41. return secret
  42.  
  43. cypher = decrypt("Hello", -7)
  44. plaint = encrypt(cypher, 7)
  45.  
  46. print cypher
  47. print plaint
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement