Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # PS this would make a great interview question
- def map_int(i, state):
- i = ord('0') + ( i + state ) % 9
- state += i
- return i, state
- def map_lower(c, state):
- x = ord('a') + (c + state ) % 25
- state += x
- return x, state
- def map_upper(c, state):
- c = ord('A') + (c + state ) % 25
- state += c
- return c, state
- def obfuscate(example):
- state=hash(example)
- example=[ord(i) for i in example]
- for i, x in enumerate(example):
- if x in range(ord('a'), ord('z') + 1):
- example[i], state = map_upper(x, state)
- elif x in range(ord('A'), ord('Z') + 1):
- example[i], state = map_lower(x, state)
- elif x in range(ord('0'), ord('9') + 1):
- example[i], state = map_int(x, state)
- example=[chr(i) for i in example]
- return ''.join(example)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement