Base58Check encoding: Difference between revisions
Content added Content deleted
m (→{{header|Phix}}: added syntax colouring, marked p2js compatible) |
|||
Line 877: | Line 877: | ||
"Rt5zm" |
"Rt5zm" |
||
</pre> |
</pre> |
||
=={{header|Picat}}== |
|||
<lang Picat>main => |
|||
Tests = [[25420294593250030202636073700053352635053786165627414518,"6UwLL9Risc3QfPqBUvKofHmBQ7wMtjvM"], |
|||
["0x61","2g"], |
|||
["0x626262", "a3gV"], |
|||
["0x636363", "aPEr"], |
|||
["0x73696d706c792061206c6f6e6720737472696e67", "2cFupjhnEsSn59qHXstmK2ffpLv2"], |
|||
["0x516b6fcd0f", "ABnLTmg"], |
|||
["0xbf4f89001e670274dd", "3SEo3LWLoPntC"], |
|||
["0x572e4794", "3EFU7m"], |
|||
["0xecac89cad93923c02321", "EJDM8drfXA6uyA"], |
|||
["0x10c8511e", "Rt5zm"]], |
|||
foreach([Test,Check] in Tests) |
|||
Res = base58Check(Test), |
|||
printf("%-56w -> %w (%s)\n", Test, Res, cond(Res==Check,"ok", "not ok")) |
|||
end, |
|||
nl. |
|||
base58Check(Hash) = Out.reverse => |
|||
CodeS = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz", |
|||
(string(Hash) -> X = Hash.to_int ; X = Hash), |
|||
Out = "", |
|||
while (X > 0) |
|||
Rem = X mod 58, |
|||
X := X // 58, |
|||
Out := Out ++ [CodeS[Rem+1]] |
|||
end.</lang> |
|||
{{out}} |
|||
<pre>25420294593250030202636073700053352635053786165627414518 -> 6UwLL9Risc3QfPqBUvKofHmBQ7wMtjvM (ok) |
|||
0x61 -> 2g (ok) |
|||
0x626262 -> a3gV (ok) |
|||
0x636363 -> aPEr (ok) |
|||
0x73696d706c792061206c6f6e6720737472696e67 -> 2cFupjhnEsSn59qHXstmK2ffpLv2 (ok) |
|||
0x516b6fcd0f -> ABnLTmg (ok) |
|||
0xbf4f89001e670274dd -> 3SEo3LWLoPntC (ok) |
|||
0x572e4794 -> 3EFU7m (ok) |
|||
0xecac89cad93923c02321 -> EJDM8drfXA6uyA (ok) |
|||
0x10c8511e -> Rt5zm (ok)</pre> |
|||
=={{header|PicoLisp}}== |
=={{header|PicoLisp}}== |