Base58Check encoding: Difference between revisions

Content added Content deleted
(Added c#)
Line 588: Line 588:


=={{header|Phix}}==
=={{header|Phix}}==
Slight variation from [[Bitcoin/public_point_to_address#Phix]] in that it accepts
Slight variation from [[Bitcoin/public_point_to_address#Phix]] in that it accepts any length string (which can be binary or text).<br>
Includes leading zeroes, if you don't want that just comment out the three lines defining/using the integer lz.
any length string (which can be binary or text).
<lang Phix>constant b58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
<lang Phix>constant b58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
function base58(string s)
function base58(string s)
string out = ""
string out = ""
integer lz = length(s)
while 1 do
while 1 do
s = trim_head(s,'\0')
s = trim_head(s,'\0')
if length(s)=0 then exit end if
if length(s)=0 then exit end if
if out="" then lz -= length(s) end if
integer c = 0
integer c = 0
for i=1 to length(s) do
for i=1 to length(s) do
Line 605: Line 607:
out &= b58[c+1]
out &= b58[c+1]
end while
end while
out &= repeat('1',lz)
return reverse(out)
return reverse(out)
end function
end function
Line 620: Line 623:
{{out}}
{{out}}
<pre>
<pre>
"16UwLL9Risc3QfPqBUvKofHmBQ7wMtjvM"
"6UwLL9Risc3QfPqBUvKofHmBQ7wMtjvM"
"2g"
"2g"
"a3gV"
"a3gV"