Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- Usage:
- Type something in (using only latin characters) and then press enter to
- convert it to base 4 into WASD
- By: Jaxrtech (with the power of Google)
- """
- def base10toN(num, base):
- """Change ``num'' to given base
- Upto base 36 is supported."""
- converted_string, modstring = "", ""
- currentnum = num
- if not 1 < base < 37:
- raise ValueError("base must be between 2 and 36")
- if not num:
- return '0'
- while currentnum:
- mod = currentnum % base
- currentnum = currentnum // base
- converted_string = chr(48 + mod + 7*(mod > 10)) + converted_string
- return converted_string
- class Offsets:
- CAPS_ALPHA = ord('A')
- def base_map(base_point, mapping):
- """
- Returns a string from a base number point converted
- with a mapping.
- >>> base_map('13', ['W', 'A', 'S', 'D'])
- 'WS'
- """
- return ''.join(mapping[int(c)-1] for c in base_point)
- WASD_MAPPING = ['W', 'A', 'S', 'D']
- BASE = 4
- SHIFT_ORIGIN = Offsets.CAPS_ALPHA
- message = raw_input().upper().split(' ')
- ascii = [map(ord, s) for s in message]
- shifted = [map(lambda x: x - SHIFT_ORIGIN, s) for s in ascii]
- base = [map(lambda x: base10toN(x, BASE), s) for s in shifted]
- base_map = [map(lambda x: base_map(x, WASD_MAPPING), s) for s in base]
- print base_map
Advertisement
Add Comment
Please, Sign In to add comment