hexathon

Common and uncommon hex string operations for python3
git clone git://git.defalsify.org/python-hexathon.git
Log | Files | Refs | LICENSE

commit cc88666420f0c52fa3e870642cbb2d0c3037ac1c
parent 3326e66452a30135cf7189b3f94b7530b6df2791
Author: nolash <dev@holbrook.no>
Date:   Wed, 17 Mar 2021 22:31:52 +0100

Add pad

Diffstat:
Mhexathon/parse.py | 18+++++++++++++++++-
Msetup.cfg | 2+-
2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/hexathon/parse.py b/hexathon/parse.py @@ -29,8 +29,24 @@ def strip_0x(hx): def add_0x(hx): - if len(hx) < 2: + if len(hx) == 0: raise ValueError('invalid hex') if hx[:2] == '0x': hx = hx[2:] return '0x' + even(hx) + + +def unpad(hx): + hx = strip_0x(hx) + i = 0 + for i in range(len(hx)): + if hx[i] != '0': + break + hx = hx[i:] + return even(hx) + + +def pad(hx, byte_length): + hx = strip_0x(hx) + hx = hx.rjust(byte_length * 2, '0') + return hx diff --git a/setup.cfg b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = hexathon -version = 0.0.1a2 +version = 0.0.1a4 description = Common and uncommon hex string operations author = Louis Holbrook author_email = dev@holbrook.no