Post
Topic
Board Auctions
Re: [BOUNTY] Mathematica fcns for RIPEMD-160 and base58 coding (0.05 BTC each)
by
CaeZaR
on 20/05/2014, 16:22:41 UTC
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:
Code:
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.
Code:
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.