Advertisement
Guest User

Untitled

a guest
Jan 15th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. import re
  2.  
  3. class cypher():
  4.  
  5. def __init__(self, text):
  6. self.text = text
  7.  
  8. def multiple_replace(text):
  9. dict = {
  10. "a": "z",
  11. "b": "y",
  12. "c": "x",
  13. "f": "u",
  14. "d": "w",
  15. "e": "v",
  16. }
  17.  
  18. # Create a regular expression from the dictionary keys
  19. regex = re.compile("(%s)" % "|".join(map(re.escape, dict.keys())))
  20.  
  21. # For each match, look-up corresponding value in dictionary
  22. return regex.sub(lambda mo: dict[mo.string[mo.start():mo.end()]], text)
  23.  
  24.  
  25. test = input(str('What do you want cyphered. '))
  26.  
  27. fixed = cypher.multiple_replace(test)
  28. print()
  29. print(fixed)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement