def translate(otp, to=MODHEX):
    """Return set() of possible modhex interpretations of a Yubikey otp.

    If otp uses all 16 characters in its alphabet, there will be only
    one possible interpretation of that Yubikey otp (except for two
    Armenian keyboard layouts).

    otp: Yubikey output.
    to: 16-character target alphabet, default MODHEX.
    """
    if PY3:
        if isinstance(otp, bytes):
            raise ValueError("otp must be unicode")
        if isinstance(to, bytes):
            raise ValueError("to must be unicode")
    else:
        if not isinstance(otp, unicode):
            raise ValueError("otp must be unicode")
        if not isinstance(to, unicode):
            raise ValueError("to must be unicode")

    possible = (set(index[c]) for c in set(otp))
    possible = reduce(lambda a, b: a.intersection(b), possible)
    translated = set()
    for i in possible:
        a = alphabets[i]
        translation = dict(zip((ord(c) for c in a), to))
        translated.add(otp.translate(translation))

    return translated
def translate ( otp , to = MODHEX ) : if PY3 : if isinstance ( otp , bytes ) : raise ValueError ( "otp must be unicode" ) if isinstance ( to , bytes ) : raise ValueError ( "to must be unicode" ) else : if not isinstance ( otp , unicode ) : raise ValueError ( "otp must be unicode" ) if not isinstance ( to , unicode ) : raise ValueError ( "to must be unicode" ) possible = ( set ( index [ c ] ) for c in set ( otp ) ) possible = reduce ( lambda a , b : a . intersection ( b ) , possible ) translated = set ( ) for i in possible : a = alphabets [ i ] translation = dict ( zip ( ( ord ( c ) for c in a ) , to ) ) translated . add ( otp . translate ( translation ) ) return translated
Return set() of possible modhex interpretations of a Yubikey otp.

    If otp uses all 16 characters in its alphabet, there will be only
    one possible interpretation of that Yubikey otp (except for two
    Armenian keyboard layouts).

    otp: Yubikey output.
    to: 16-character target alphabet, default MODHEX.