I am trying to convert a string encoded variable (which originally is a hex guid) into the hex guid and back to the same string encoded version.
I am doing this using base64 package of the python standard library
>>> import base64
>>> guid
'Dw8OAwQFBgcIBQABAgMEBw==\n'
>>> cguid=base64.decodestring(guid).encode('hex')
'0f0f0e03040506070805000102030407'
Above code accomplishes the task. Now I need to convert the variable cguid back to guid.
How do I accomplish the task?
I have tried switching the decode and encode but it does not seem to work. It shows me an error.
>>> base64.encodestring(cguid).decode('hex')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/nb/python/lib/python2.7/encodings/hex_codec.py", line 42, in hex_decode
output = binascii.a2b_hex(input)
TypeError: Odd-length string
>>>