Base 32 and base 64 encoding

There’s no firm convention for whether to use upper or lower case letters.Base 64 encodingThe common use for base 64 encoding isn’t to represent bits as numbers per se, but to have an efficient way to transmit bits in a context that requires text characters.There are around 100 possible characters on a keyboard, and 64 is the largest power of 2 less than 100 [1], and so base 64 is the most dense encoding using common characters in a base that is a power of 2.Base 64 encoding does not follow the math convention of using the digits first and then adding more symbols; it’s free not to because there’s no intention of treating the output as numbers..Instead, the capital letters A through Z represent the numbers 0 though 25, the lower case letters a through z represent the numbers 26 through 51, and the digits 0 through 9 represent the numbers 52 through 61..The symbol + is used for 62 and / is used for 63.Crockford’s base 32 encodingDouglas Crockford proposed an interesting form of base 32 encoding..His encoding mostly follows the math convention: 0, 1, 2, …, 9, A, B, …, except he does not use the letters I, L, O, and U..This eliminates the possibility of confusing i, I, or l with 1, or confusing O with 0..Crockford had one more letter he could eliminate, and he chose U in order to avoid an “accidental obscenity.” [2]Crockford’s base 32 encoding is a compromise between efficiency and human legibility..It is more efficient than hexadecimal, representing 25% more bits per character..It’s less efficient than base 64, representing 17% fewer bits per character, but is more legible than base 64 encoding because it eliminates commonly confused characters.His encoding is also case insensitive..He recommends using only capital letters for output, but permitting upper or lower case letters in input..This is in the spirit of Postel’s law, also known as the robustness principle:Be conservative in what you send, and liberal in what you accept.See the next post for an explanation of Crockford’s check sum proposal.A password generatorHere’s a Python script to generate passwords using Crockford’s base 32 encoding..from secrets import randbits from base32_crockford import encode def gen_pwd(numbits): print(encode(randbits(numbits))) For example, gen_pwd(60) would create a 12-character password with 60-bits of entropy, and this password would be free of commonly confused characters.Related postsOnline radix conversionWords that are prime in base 36[1] We want to use powers of 2 because it’s easy to convert between base 2 and base 2n: start at the right end and convert bits in groups of n..For example, to convert a binary string to hexadecimal (base 24 = 16), convert groups of four bits each to hexadecimal.. More details

Leave a Reply