Skip to content

Instantly share code, notes, and snippets.

View LukeMurphey's full-sized avatar

Luke LukeMurphey

View GitHub Profile
@LukeMurphey
LukeMurphey / md4.py
Last active December 6, 2016 01:24 — forked from tristanwietsma/md4.py
MD4 in pure Python 2.7. Backported from Andrew Cooke's Python 3.3 implementation. (http://www.acooke.org/cute/PurePython0.html). This version returns the same value that hashlib would have (making it a drop in replacement).
from array import array
from string import join
from struct import pack, unpack
_DECODE = lambda x, e: list(array('B', x.decode(e)))
_ENCODE = lambda x, e: join([chr(i) for i in x], '').encode(e)
HEX_TO_BYTES = lambda x: _DECODE(x, 'hex')
TXT_TO_BYTES = lambda x: HEX_TO_BYTES(x.encode('hex'))
BYTES_TO_HEX = lambda x: _ENCODE(x, 'hex')
BYTES_TO_TXT = lambda x: BYTES_TO_HEX(x).decode('hex')