Advertisement
Guest User

Untitled

a guest
Dec 5th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. import re
  2.  
  3. pattern = r"^[A-Z][a-z' ]+:[A-Z ]+$"
  4.  
  5. text = input()
  6.  
  7. while text != "end":
  8. encrypted_string = ""
  9. matches = re.findall(pattern, text)
  10. if not matches:
  11. print("Invalid input!")
  12. else:
  13. for m in matches:
  14. artist, song = m.split(":")
  15. key = len(artist)
  16. for char in m:
  17. if char == ":":
  18. encrypted_string += "@"
  19. elif char == " " or char == "'":
  20. encrypted_string += char
  21. elif char.isupper():
  22. if ord(char) + key > 90:
  23. start_from = (ord(char) + key) - 90
  24. encrypted_string += chr(64 + start_from)
  25. else:
  26. encrypted_string += chr(ord(char) + key)
  27. elif char.islower():
  28. if ord(char) + key > 122:
  29. start_from = (ord(char) + key) - 122
  30. encrypted_string += chr(96 + start_from)
  31. else:
  32. encrypted_string += chr(ord(char) + key)
  33. print(f"Successful encryption: {encrypted_string}")
  34. text = input()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement