Yubico Forum
https://forum.yubico.com/

Easy modhex routines in Python
https://forum.yubico.com/viewtopic.php?f=8&t=187
Page 1 of 1

Author:  kseistrup [ Sat Sep 20, 2008 9:33 pm ]
Post subject:  Easy modhex routines in Python

Code:
hexHexChars = '0123456789abcdef'
modHexChars = 'cbdefghijklnrtuv'

hex2ModDict = dict(zip(hexHexChars, modHexChars))
mod2HexDict = dict(zip(modHexChars, hexHexChars))

def modhex_encode(s):
    return ''.join(
        [ hex2ModDict[c] for c in s.encode('hex') ]
    )
# end def modhex_encode

def modhex_decode(m):
    return ''.join(
        [ mod2HexDict[c] for c in m ]
    ).decode('hex')
# end def modhex_decode

Page 1 of 1 All times are UTC + 1 hour
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/