diff options
Diffstat (limited to 'python/001-hexstring2bytes.py')
-rw-r--r-- | python/001-hexstring2bytes.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/python/001-hexstring2bytes.py b/python/001-hexstring2bytes.py new file mode 100644 index 0000000..22de43d --- /dev/null +++ b/python/001-hexstring2bytes.py @@ -0,0 +1,11 @@ +# we only consider absolute value (for tha case of "-0x..." hexstr parameter) +# presumably damn slow, but should work for magic strings with uknown length +hexstring2bytes = \ + lambda hexstr: \ + reduce( + lambda acc, (i, x): + acc[:-1] + chr(int(x + hex(ord(acc[-1]))[-1], 16)) if i % 2 + else acc + chr(int(x, 16)), + enumerate(reversed(hexstr.lstrip('-0x'))), + '' + ) |