Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.