Decode a string of hexadecimaldigits into a byte string or encode a byte string as hex.
>>> s = b'hello'
>>> import binascii
# encode as hex
>>> h = binascii.b2a_hex(s)
>>> h
b'68656c6c6f'
# decode back to bytes
>>> binascii.a2b_hex(h)
b'hello'
>>>
>>> import base64
>>> h = base64.b16encode(s)
>>> h
b'68656C6C6F'
>>> base64.b16decode(h)
b'hello'
decode/encode binary data using base64 encoding.
>>> a = base64.b64encode(s)
>>> a
b'aGVsbG8='
>>> base64.b64decode(a)
b'hello'
>>> s = b'hello'
>>> import binascii
# encode as hex
>>> h = binascii.b2a_hex(s)
>>> h
b'68656c6c6f'
# decode back to bytes
>>> binascii.a2b_hex(h)
b'hello'
>>>
>>> import base64
>>> h = base64.b16encode(s)
>>> h
b'68656C6C6F'
>>> base64.b16decode(h)
b'hello'
decode/encode binary data using base64 encoding.
>>> a = base64.b64encode(s)
>>> a
b'aGVsbG8='
>>> base64.b64decode(a)
b'hello'
Comments
Post a Comment
https://gengwg.blogspot.com/