Version 13 of base58

Updated 2011-08-05 01:30:49 by aspect

Like base64, but without these characters: +/0OIl

This is the definition of base58 as used by the open source decentralized cryptographic peer-to-peer currency system bitcoin. (there is apparently a different version of base58 used by Flickr)

The rationale (at least for bitcoin) behind the use of base58 is:

  • Don't want 0OIl characters that look the same in some fonts and could be used to create visually identical looking account numbers.
  • A string with non-alphanumeric characters is not as easily accepted as an account number.
  • E-mail usually won't line-break if there's no punctuation to break at.
  • Doubleclicking selects the whole number as one word if it's all alphanumeric.

The alphabet used is: "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"


JMN 2011-06-28 Does anyone know if there are existing Tcl implementations of base58 as used by bitcoin?


AK - 2011-06-28 17:41:27

I do not know of any implementation. If one is made by whoever I would strongly recommend to submit the code to Tcllib for inclusion, as it already has base64, base32, ascii85, uu, yEnc, etc. I.e. a base58 implementation would fit right in.


aspect: this came up in the Tcl Chatroom so I did a quick implementation. base58 is not so good for encoding binary chunks, as it doesn't correspond neatly to a length in bits. This version base58-encodes an integer:

proc base32 {int {alphabet 123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz}} {
  set result {}
  set alen [string length $alphabet]
  while {$int} {
    set result $result[string index $alphabet [expr {$int%$alen}]]
    set int [expr {$int/$alen}]
  }
  set result
}

An example usage to generate unique identifiers a la youtube might be:

package require md5
string range [base58 [md5::md5 -hex "myidentifier"]] 0 11

Whether your identifiers are sufficiently unique is a matter for you to decide ..