lørdag den 20. september 2008

Python modhex


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