Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. # PS this would make a great interview question
  2.  
  3. def map_int(i, state):
  4. i = ord('0') + ( i + state ) % 9
  5. state += i
  6. return i, state
  7.  
  8. def map_lower(c, state):
  9. x = ord('a') + (c + state ) % 25
  10. state += x
  11. return x, state
  12.  
  13. def map_upper(c, state):
  14. c = ord('A') + (c + state ) % 25
  15. state += c
  16. return c, state
  17.  
  18. def obfuscate(example):
  19. state=hash(example)
  20.  
  21. example=[ord(i) for i in example]
  22. for i, x in enumerate(example):
  23. if x in range(ord('a'), ord('z') + 1):
  24. example[i], state = map_upper(x, state)
  25. elif x in range(ord('A'), ord('Z') + 1):
  26. example[i], state = map_lower(x, state)
  27. elif x in range(ord('0'), ord('9') + 1):
  28. example[i], state = map_int(x, state)
  29.  
  30. example=[chr(i) for i in example]
  31. return ''.join(example)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement