Bitcoin/address validation: Difference between revisions

Content added Content deleted
m (rev4 now in sha256.e)
Line 1,399: Line 1,399:
end if
end if
return out
return out
end function

function rev4(string s)
string res = ""
for i=1 to length(s)-3 by 4 do
for j=i+3 to i by -1 do
res &= s[j]
end for
end for
return res
end function
end function


Line 1,415: Line 1,405:
procedure valid(string s)
procedure valid(string s)
object dec
object dec
sequence d1, d2
coin_err = "OK"
coin_err = "OK"
dec = unbase58(s)
dec = unbase58(s)
if string(dec) then
if string(dec) then
d1 = sha256(dec[1..21])
if dec[22..$]!=sha256(sha256(dec[1..21]))[1..4] then
d2 = rev4(sha256(rev4(d1)))
if dec[22..$]!=d2[1..4] then
coin_err = "bad digest"
coin_err = "bad digest"
end if
end if
Line 1,441: Line 1,428:
"1badbadbadbadbadbadbadbadbadbadbad", -- not version 0
"1badbadbadbadbadbadbadbadbadbadbad", -- not version 0
"BZbvjr", -- first character is not 1 or 3 (checksum is fine, address too short)
"BZbvjr", -- first character is not 1 or 3 (checksum is fine, address too short)
"16UwLL9Risc3QfPqBUvKofHmBQ7wMtjvM", -- OK (from public_point_to_address)
$}
$}