diff options
author | Jan Pokorný <jpokorny@redhat.com> | 2014-10-02 22:11:39 +0200 |
---|---|---|
committer | Jan Pokorný <jpokorny@redhat.com> | 2014-10-02 22:11:39 +0200 |
commit | 01df9960e6bd4a99d982eae32182d86146498812 (patch) | |
tree | ee2475ed3b08a40c89527673ce1e85e54ac2fea0 | |
parent | d6a4f12955180d99c85edb853166adb7791f856f (diff) | |
download | snippets-01df9960e6bd4a99d982eae32182d86146498812.tar.gz snippets-01df9960e6bd4a99d982eae32182d86146498812.tar.xz snippets-01df9960e6bd4a99d982eae32182d86146498812.zip |
Add python/001-hexstring2bytes.py
Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
-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'))), + '' + ) |