I realize I botched this when I caught that after z should come 21 not 11 (all the leading unprinted digits are 1s), so here is the fixed version:
Options[Base58Encode] = {n -> None};
Base58Encode[x_Integer, OptionsPattern[]] :=
StringJoin[
StringTake[
"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",
Partition[
1 + If[OptionValue[n] === None, IntegerDigits[x, 58],
IntegerDigits[x, 58, OptionValue[n]]], 1]]]
You can call it with a single parameter and get the shortest version of the number, or specify the number of digits (n) as an option.
i = RandomInteger[2^256]
Base58Encode[i]
Base58Encode[i, n -> 50]
I'll fix the decode in the next post, as it is wrong too. Sorry about that.