5 ms·
If you're going to change the order defined in RFC 4648, you might as well change the character set, too. Since one of the goals is to minimize the use of chara
by kijin 4y ago
If you're going to change the order defined in RFC 4648, you might as well change the character set, too. Since one of the goals is to minimize the use of characters that can be confused for another, I would add back 8 and 9 and remove two of i, l and o.
- junon 4y agoThis is what crockford32 does by the way. It's my preferred base32 alternative when there's a chance humans have to transmit something.
- gmac 4y agoI like to also remove 0 and 1 — because the human entering the code probably doesn't know that 0, o and O will be considered equivalent — and A and E — because accidental profanity isn't actually prevented by excluding only U and I. This gives base 28, of course, which is admittedly slightly less neat, but still perfectly usable. For example, in TypeScript I use this: const targetChars = '23456789bcdfghjkmnpqrstvwxyz'; // must be <=36 chars const sourceChars = '0123456789abcdefghijklmnopqr'; // what we get from toString(radix) const radix = targetChars.length; export function tokenFromId(id: number) { return [...id.toString(radix)] .map(origChar => targetChars.charAt(sourceChars.indexOf(origChar))) .join(''); } export function idFromToken(token: string) { return parseInt([...token.toLowerCase()] .map(pathChar => sourceChars.charAt(targetChars.indexOf(pathChar))) .join('') , radix); }
- junon 4y agoTo each their own, but the point is that the human doesn't need to know that 0, o and O are considered the same.