7 ms·
The Base58 Encoding Scheme
- heydenberk 6y agoTL;DR: Uppercase and lowercase alphabet plus numbers, which would be 62 characters, except it omits uppercase I (as in India), lowercase l (as in lima), capital O (as in Oscar) and the number 0, as they're all visually similar and sometimes indistinct with other characters.
- eknkc 6y agoThe Node module base-x (https://www.npmjs.com/package/base-x https://www.npmjs.com/package/base-x) can be used to encode and decode these using the alphabet 123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz Shameless plug: I have a port of it in Go (https://github.com/eknkc/basex https://github.com/eknkc/basex) and .NET (https://github.com/eknkc/basex-dotnet https://github.com/eknkc/basex-dotnet)
- deleted 6y ago[deleted]
- gclawes 6y agoI feel like base64 is "good enough" and well supported pretty much everywhere that I'm skeptical of trying to convert to a new slightly better format.
- tosh 6y agoone of the main annoyances w/ base64 is when you want to it in the context of URLs https://en.wikipedia.org/wiki/Base64#URL_applications https://en.wikipedia.org/wiki/Base64#URL_applications > Using standard Base64 in URL requires encoding of '+', '/' and '=' characters into special percent-encoded hexadecimal sequences ('+' becomes '%2B', '/' becomes '%2F' and '=' becomes '%3D'), which makes the string unnecessarily longer.
- tracker1 6y agofor URIs, would use base64url. Replaces '+' with '-' and '/' with '_' while omitting the '=' padding.
- jillesvangurp 6y agoApache commons codec has a base 64 encoder that has a url friendly mode where it substitutes those characters. I've used that a few times to work around issues like this.
- brabel 6y agoURL-safe base64 is part of the spec: https://tools.ietf.org/html/rfc4648#section-5 https://tools.ietf.org/html/rfc4648#section-5 If you're using Java, it's right in the standard library: `Base64.getUrlEncoder().withoutPadding().encode(value)`
- xerxesaa 6y agoThis is not the purpose of base58. The main use case for base58 is to avoid human error in similar looking characters ("l" vs I" or "0" vs "O"). As an example, this is used in Bitcoin addresses to ensure you don't accidentally type the wrong characters if copying an address by hand.
- mleonhard 6y agoYet it leaves in several easily confused character pairs: 5S, and 8B.
- CivBase 6y agoI recently wrote a base64 encoder/decoder at work. Luckily, I did not need to make it compatible with other base64 encoders/decoders because, as the article points out... > Base64 has eleven encoding variations that lead to confusion among developers on which variety of Base64 to use. Each variation has its own niche (URL safe characters, filename safe characters, checksum support, etc). I see Base58 as basically just another variation of Base64 with its own niche (human friendly characters). There's no need for existing apps to "convert". If their current Base64 implementation is good enough, they'll stick with it. Base58 is just another variation to consider when developing something new.
- CydeWeys 6y agoBase58 has existed for over a decade now, so I wouldn't exactly call it a "new" format at this point. And I've been using it for almost that long, so it's old hat to me.
- wp381640 6y agoThat’s draft 1 from 2019, draft 2 from a couple months ago which adds more and fixes the test vectors is here: https://tools.ietf.org/html/draft-msporny-base58-02 https://tools.ietf.org/html/draft-msporny-base58-02 Also of note is that Bitcoin has since moved onto bech32 - the shortcomings of base56 are discussed in the first section: https://en.bitcoin.it/wiki/BIP_0173 https://en.bitcoin.it/wiki/BIP_0173 Pieter Wuille’s talk on the design and motivations is great: https://youtu.be/NqiN9VFE4CU https://youtu.be/NqiN9VFE4CU
- raxxorrax 6y agoSo basically remove all the funny symbols and the ambiguous characters of the latin alphabet. The part "Test Vectors" seems to be formatted wrongly. 2NEpo7TZRRrLZSi2U is "Hello World!" and the long stuff probably the fox thingy. Otherwise it is a good idea in my opinion, didn't know it existed and should perform well.
- jasperry 6y agoThese human-readable encoding systems are nifty, but a higher goal is to design secure systems that don't require humans to read or type (or copy and paste) random strings of bytes. For techies, occasionally eyeballing a hash as an informal check will continue to be useful, but I can't imagine that confusing 1 and l would ever be an issue in that use case.
- rini17 6y agoIn a secure system there is always going to be an airgap with a need for human to check what went over the gap before committing the transaction. Nonrandom strings of bytes, such as names, are also spoofable, so not much better in this regard.
- deleted 6y ago[deleted]
- reactor 6y agoUnderstand they removed '0' & 'O' but why did they retain 'o' as it could be confusing with '0', 'O'?
- deleted 6y ago[deleted]
- sjnu 6y agoIt's safe to leave behind one of each group (1 is still there).
- quesera 6y agoThat's true -- the parser can just translate any lookalike errors into the canonical character. But I wish the standard was to keep all digits and drop the lookalike letters. I can't think of a reason for the extra (human) burden of remembering whether it's 0 over O, or I over 1, etc.
- deleted 6y ago[deleted]
- nicky0 6y agoThe decoder can simply replace 0 and O with o. Human error will thus be corrected and you can relax and use any of them.
- quesera 6y agoI'm thinking more from the parser side. Being liberal in what you accept is fine, but being strict in what you emit requires extra mental overhead. It's nothing cataclysmic (and "on the developer" is a often a reasonable place to add the extra overhead) but in this case it seems like selecting 0 instead of O or o, and 1 instead of I or l, would have been more straightforward. Selecting "1" (ASCII 49), and "o" (ASCII 111) is inconsistent and feels odd. EDIT: OK, I can think of one possible justification: with zero disallowed, a leading zero can never be lost. In a short Base58 string, it's not unusual for all characters to be numeric, and some overzealous readers will interpret the whole value as an integer. See also: hex strings, US ZIP codes, ABA routing numbers, etc, vs Microsoft Excel. :) EDIT2: Nevermind, that's a lame justification. The likelihood of a Base58 string of any useful length containing numeric chars only is very low, since the alphabet would be 17.2% numeric) unlike hex strings (61.5% numeric), or ZIP codes and ABA numbers (100% numeric). Additionally, IIRC Base58 was invented for BTC addresses, which necessarily started (at the time) with a "1" char (now "1", "3", or "bc1").
- deleted 6y ago[deleted]
- deleted 6y ago[deleted]
- duffyjp 6y agoI used Base52 (no vowels) for a big project a couple years ago. It prevents your numeric ID from being converted into a naughty word. https://duffyjp.github.io/2019/04/12/Base-52.html https://duffyjp.github.io/2019/04/12/Base-52.html
- hinkley 6y agoEvery time someone posts about Base-X encoding I have a little nostalgia for the Base-94 encoding I wrote as probably the first program I wrote from scratch solo (my idea, my design, my implementation), or the funky Base-32 design we did for a dev tool. We had a new team lead who was a night owl like me. One day everyone left early but he and I were sitting around, and one of us, I forget who, was trying to implement a URL slug format that had the following qualities, ordered by priority: * does not require URL encoding * can be dictated or transcribed easily (it was a dev tool, in a time when pasting a URL into chat was not a given) * as much as possible, could not contain swear words We nerd-sniped each other into spending a couple of hours coming up with an odd-ball base-32 implementation with no homographs, and also that as long as you have vowels and leetspeak numbers you'd get swear words. So we started with base 64 minus the symbols, vowels+y, homographs and leetspeak numbers, leaving us somewhere around 40 symbols left, so we just started removing consonants common in swears, starting with epithets and working backward. shtccks4vr is a bad url, but stick c--t or the n-word in a URL and HR is going to definitely have a talk with you then write an angry letter to us. Especially with a selection of choice verbs in the same slug...
- ezekiel68 6y agoI must admit -- I find the comments here which mention concern about encodings containing swear words or naughty words to be ridiculous. Most encoded values are not exposed to users other than long query string values as http session tokens and such. Are we trying to spare the virgin eyes (ROFL) of our fellow engineers who may browse through database rows? Seems like wasted mental cycles to me.
- viluon 6y agoNot to mention it's foolish to think that such a "swear-proof" encoding doesn't allow swear words in languages other than English.