Posted By

kseistrup on 02/12/09


Tagged

python filter encode decode modhex


Versions (?)

modhex coding


 / Published in: Python
 

URL: http://bit.ly/4jags

Convert to and from modHex as used by the yubikey from yubico.

  1. hexHexChars = '0123456789abcdef'
  2. modHexChars = 'cbdefghijklnrtuv'
  3.  
  4. hex2ModDict = dict(zip(hexHexChars, modHexChars))
  5. mod2HexDict = dict(zip(modHexChars, hexHexChars))
  6.  
  7. def modhex_encode(s):
  8. return ''.join(
  9. [ hex2ModDict[c] for c in s.encode('hex') ]
  10. )
  11. # end def modhex_encode
  12.  
  13. def modhex_decode(m):
  14. return ''.join(
  15. [ mod2HexDict[c] for c in m ]
  16. ).decode('hex')
  17. # end def modhex_decode

Report this snippet  

You need to login to post a comment.