I've got a bunch of bytes I want to output in a human-friendly fashion (using characters that will be available and printable in any font/encoding/etc.). In my case, the bytes are the result of an md5 sum:
import hashlib
h = hashlib.md5("foo")
The HASH
object has two ways of displaying its contents to me.
print h.digest() # Uses a bunch of unprintable characters
print h.hexdigest() # Readable, but 32 characters long
The second option gives me a well-behaved string of characters that I can read, cut and paste, or whatever. But it's an inefficient representation: it only uses 16 characters because it's hexadecimal. It could give me a shorter string if it used the whole alphabet, uppercase letters, punctuation, etc. Can I get a shorter, denser digest by expanding beyond hex?