Base58Check encoding: Difference between revisions
Content added Content deleted
(→{{header|Go}}: More idiomatic error handling.) |
|||
Line 501: | Line 501: | ||
} |
} |
||
</lang> |
</lang> |
||
=={{header|Phix}}== |
|||
Slight variation from [[Bitcoin/public_point_to_address#Phix]] in that it accepts |
|||
any length string (which can be binary or text). |
|||
<lang Phix>constant b58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz" |
|||
function base58(string s) |
|||
string out = "" |
|||
while 1 do |
|||
s = trim_head(s,'\0') |
|||
if length(s)=0 then exit end if |
|||
integer c = 0 |
|||
for i=1 to length(s) do |
|||
c = c*256+s[i] |
|||
s[i] = floor(c/58) |
|||
c = mod(c,58) |
|||
end for |
|||
out &= b58[c+1] |
|||
end while |
|||
return reverse(out) |
|||
end function |
|||
?base58(x"00010966776006953D5567439E5E39F86A0D273BEED61967F6") |
|||
?base58(x"61") |
|||
?base58(x"626262") |
|||
?base58(x"636363") |
|||
?base58(x"73696d706c792061206c6f6e6720737472696e67") |
|||
?base58(x"516b6fcd0f") |
|||
?base58(x"bf4f89001e670274dd") |
|||
?base58(x"572e4794") |
|||
?base58(x"ecac89cad93923c02321") |
|||
?base58(x"10c8511e")</lang> |
|||
{{out}} |
|||
<pre> |
|||
"6UwLL9Risc3QfPqBUvKofHmBQ7wMtjvM" |
|||
"2g" |
|||
"a3gV" |
|||
"aPEr" |
|||
"2cFupjhnEsSn59qHXstmK2ffpLv2" |
|||
"ABnLTmg" |
|||
"3SEo3LWLoPntC" |
|||
"3EFU7m" |
|||
"EJDM8drfXA6uyA" |
|||
"Rt5zm" |
|||
</pre> |
|||
=={{header|Racket}}== |
=={{header|Racket}}== |