Skip to content

Instantly share code, notes, and snippets.

@brianmhunt
Created January 3, 2015 20:27
Show Gist options
  • Save brianmhunt/09a82cbda559cfcc47dd to your computer and use it in GitHub Desktop.
Save brianmhunt/09a82cbda559cfcc47dd to your computer and use it in GitHub Desktop.

Revisions

  1. brianmhunt created this gist Jan 3, 2015.
    30 changes: 30 additions & 0 deletions trepid.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    """
    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)