public static string Encode(byte[] input)
{
// TODO: This could be a lot more efficient.
var bi = new BigInteger(1, input);
var s = new StringBuilder();
while (bi.CompareTo(_base) >= 0)
{
var mod = bi.Mod(_base);
s.Insert(0, new[] {_alphabet[mod.IntValue]});
bi = bi.Subtract(mod).Divide(_base);
}
s.Insert(0, new[] {_alphabet[bi.IntValue]});
// Convert leading zeros too.
foreach (var anInput in input)
{
if (anInput == 0)
s.Insert(0, new[] {_alphabet[0]});
else
break;
}
return s.ToString();
}
public override string ToString() { // A stringified buffer is: // 1 byte version + data bytes hash + 4 bytes check code (itself a truncated hash) var addressBytes = new byte[1 + Bytes.Length + 4]; addressBytes[0] = (byte)Version; Array.Copy(Bytes, 0, addressBytes, 1, Bytes.Length); var check = Utils.DoubleDigest(addressBytes, 0, Bytes.Length + 1); Array.Copy(check, 0, addressBytes, Bytes.Length + 1, 4); return(Base58.Encode(addressBytes)); }