Skip to content

Instantly share code, notes, and snippets.

@brianmhunt
Created January 3, 2015 20:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brianmhunt/09a82cbda559cfcc47dd to your computer and use it in GitHub Desktop.
Save brianmhunt/09a82cbda559cfcc47dd to your computer and use it in GitHub Desktop.
Human UX strings mapping
"""
Human UX strings mapping
See http://stackoverflow.com/a/27459196
0 1 2 3 4 5 6 7 8 9 A B C D E F Hexadecimal
H M N 3 4 P 6 7 R 9 T W C X Y F Replacement
Y = U = V
C = G
X = K
F = E
"""
import string
trans_table = string.maketrans(
"HMN34P67R9TWCGXKYUVFE",
"0123456789ABCCDDEEEFF"
)
def translate(str):
"""Normalize to an unambiguous Base16 string
>>> translate("hmn34P67r9")
'0123456789'
>>> translate("WCGXKYUVFE")
'BCCDDEEEFF'
"""
return str.upper().translate(trans_table)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment