Live data from Hacker News

How does Base32 (or any Base2^n) work exactly?

ptrchm.com

21–30 of 46 posts

Re: How does Base32 (or any Base2^n) work exactly?

#21
post #5

Hey Piotr/pchm, I'm not sure I follow your argument that Base32 is less popular because it's not a standard (there is a standard - RFC4648 as you mention). Not implementing the RFC, is not implementing Base32, changing the order, or using 32 emoji does not make it Base32. Put another way, you can change the order of characters in Base64, or use a different dictionary, and indeed there are several variants of that too…

You make some good points. What I was trying to say is that even though there is the RFC, it's quite common to modify the alphabet or use other variants like Crockford's (mainly to avoid random profanity, e.g. in the URL identifiers).

When you see a Base64 string, you can be pretty certain that it's the standard version. With Base32, it's not obvious which variant was used.

Many languages don't provide a stdlib Base32 implementation (Ruby doesn't), but Base64 is pretty much always included. Maybe this influenced my perception of the lack of a universal standard.

Anyway, I should work on that section to communicate my point better.

Re: How does Base32 (or any Base2^n) work exactly?

#22
post #3

A few other bases that are interesting: Base36: 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ Good encoding for binary data in textual contexts. Such as where you have parameter inputs or database fields that are constrained and only accept certain characters. The lack of spaces means that it can be used on the command-line easily. Example use: IRC channel names. Base64: 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrs…

> base36 textual contexts Better IMO is base 32 with U (obscenity), 0/O (ambiguity), and I (ambiguity) removed.

What makes the letter U obscene?

Re: How does Base32 (or any Base2^n) work exactly?

#24
post #3

A few other bases that are interesting: Base36: 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ Good encoding for binary data in textual contexts. Such as where you have parameter inputs or database fields that are constrained and only accept certain characters. The lack of spaces means that it can be used on the command-line easily. Example use: IRC channel names. Base64: 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrs…

That is not base64, it's base62. You can tell because it only has 62 symbols. To get base64 you have to add 2 symbols that you arbitrarily select from the master "table of symbols to add to base62 to get to base64 depending on what the platform is and what characters are restricted in it" [1]. For instance you might use `@`, except in an email. Or `/`, but not in an fs path or URL. As for base92, those symbols might…

Base62 is fantastic for URL-friendly encoding. I use GUIDs for primary keys in my web app, and encode them for frontend consumption using Base62. Looks much neater and doesn't cause issues like Base64 extra characters might.

Re: How does Base32 (or any Base2^n) work exactly?

#25
post #21
post #5

Hey Piotr/pchm, I'm not sure I follow your argument that Base32 is less popular because it's not a standard (there is a standard - RFC4648 as you mention). Not implementing the RFC, is not implementing Base32, changing the order, or using 32 emoji does not make it Base32. Put another way, you can change the order of characters in Base64, or use a different dictionary, and indeed there are several variants of that too…

You make some good points. What I was trying to say is that even though there is the RFC, it's quite common to modify the alphabet or use other variants like Crockford's (mainly to avoid random profanity, e.g. in the URL identifiers). When you see a Base64 string, you can be pretty certain that it's the standard version. With Base32, it's not obvious which variant was used. Many languages don't provide a stdlib Base3…

In some cases (luck of the data, but often when encoding ASCII without padding) you won't see the non alphanumeric characters (62nd and 63rd place) in Base64 either. So you can't always tell the difference between Base64, Base64Url, Xxencode, or B64.

"Hello, world!" = `SGVsbG8sIHdvcmxkIQ` (base64, base64url), `BG4JgP4wg65RjQalY6E` (Xxencode), or `G4JgP4wg65RjQalY6E` (b64). A legitimate reason for choosing B64 over Base64 would be: it maintains ASCII sort-order.

Any language that has to deal with HTTP (or MIME) has to encode/decode Base64 in order to support some headers (eg Basic auth) and features (binary data from a form submission). There is no similar HTTP need for Base32, so perhaps it's less surprising it's not in the standard library?

Re: How does Base32 (or any Base2^n) work exactly?

#28
Base32 encouraged me to develop my own Base32-encoder on .NET. I eventually added other encoding types over the years, leading to the library called SimpleBase. It's now being used by popular packages like Ipfs.Core, net-dns, and KubeOps.

https://github.com/ssg/SimpleBase

Re: How does Base32 (or any Base2^n) work exactly?

#29

I’m a big fan of base58 + almost as efficient as base64 + no special characters + no padding characters

Unlike Base64 or Base32, Base58 has approximately O(N^2) complexity because it requires iterative division and multiplication operations on big integers. You can't encode a gigabyte of data with Base58 in a reasonable time, but you certainly can with Base64 or Base32.
Post reply on HN