Post
Topic
Board Auctions
Re: [BOUNTY] Mathematica fcns for RIPEMD-160 and base58 coding (0.05 BTC each)
by
Peter R
on 20/05/2014, 20:12:11 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.


Hello CaeZar.  I like the way you tested the encode/decode functions using the random list.  That's what I do too. 

Your encode function is not quite correct, however.  It is still not dealing with the leading "1"s properly.  I think the option value "n" needs to be the amount of bytes to assume the number being encoded is composed of.  And then add a "1" for every byte that is zero.  The encoding for bitcoin is strange.  It is documented here and we were discussing it here

Like I said in the OP, you can fix this and resubmit to claim the bounty.