For the love of computing: Did you mean 0 or O?

We have all been in the position of not knowing if we have a zero (‘0’) or an ‘O’. So how do we avoid this? Well in the encoding of…

For the love of computing: Did you mean 0 or O?

We have all been in the position of not knowing if we have a zero (‘0’) or an ‘O’. So how do we avoid this? Well in the encoding of non-printing characters to printable ones we often Base-64, where we take six bits at a time and convert to a Base-64 character.

But what about similar-looking letters : 0 (zero), O (capital o), I (capital i) and l (lower case L), and non-alphanumeric characters of + (plus) and / (slash). The solution is Base-58 where we remove the characters which are similar looking.

In the conversion of a string to Base-58, we convert the ASCII characters into binary, and the keep dividing by 58 and convert the remainder to a Base-58 character. The alphabet becomes (notice that ‘0’ (zero), ‘O’ (capital ‘o’) and ‘I’ (capital ‘i’):

‘123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz’

So let’s take an example of ‘e’. With ‘e’ we have a decimal value of 101, so we divide by 58 to get:

1 remainder 43

and next we divide 1 by 58 and we get:

0 remainder 1

So we take character at position 1 and at position 43, to give:

123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz

and the conversion is thus:

‘2k’

If we now take ‘ef’, we get 25958 (102 + 101 * 256), where we move each character up one byte. Basically, we take the binary value of the string and then divide by 58 and take the remainder. So ‘ef’ is ‘01100101 01100110’, and when we divide we get:

25959 divide by 58 gives: 447 r 32
447 divided by 58 gives: 7 r 41
7 divided by 58 gives: 0 r 7

this gives ‘8iZ’

Here is a calculator:

Base-58 and Bitcoin addresses

So where is it used? Ans: In Bitcoin address.

With bitcoins we create a 256-bit random for the private key, and then convert it to Wallet Interchange Format key (WiF) format, which is a Base-58 form for the random key. This is the format that is stored in the Bitcoin Wallet. For example a sample private key is:

Private key: 5c04990cf2fb95ca8749d4021100ee98b0744e81a5ec00a2177aeaf4b29c00d3

We then convert this into WiF format (Base-58) to give:

5JWp4FM7sfAAE88DW3yvGF5mQyrsEXeWzXZn79bg61Vg8YMfJjA

This can be stored in a Bitcoin wallet. Next we can take then private key and a hash value, and convert it into a useable Bitcoin address, such as:

1A3CohNBuB6kFAMtp3KFEYwv3Eu58F2HyN

The format of the keys is defined below, where we create a 256-bit private key and convert this to a WiF private key. Next we generate a 512-bit public key, and then take a 160-bit RIPEM-160 hash and convert to a Bitcoin address:

Here is an example:

Conclusions

The crypto in Bitcoins is rather wacky, and is a jumble of methods, but no-one can say it doesn’t work. The crypto punks of the 1990s saw a new world, and built it with the methods that were around at time, and the built one of the most amazing infrastructures that has ever been created.