Base58Check encoding: Difference between revisions

m
→‎version 3: simplified code, changed comments and whitespace.
(Added Quackery.)
m (→‎version 3: simplified code, changed comments and whitespace.)
Line 1,224:
The algorithm used doesn't need to   ''reverse''   the residual string   (it uses   ''prepend''   instead of   ''append'').
<lang rexx>/*REXX pgm encodes a checksum (hash digest) into Base58 (the standard Bitcoin alphabet).*/
/* /* 0─────────────────I─────O────────────────────l──────────────── ◄───omit.*/
call B58 25420294593250030202636073700053352635053786165627414518
@= space(" 123456789ABCDEFGH JKLMN PQRSTUVWXYZabcdefghi jkmnopqrstuvwxyz", 0)
call B58 '61'x
exit numeric digits 500 /*stick a forkjust in it, case wethere're allhuge donenumberss. */
call B58 '626262'x
callsay B58 (25420294593250030202636073700053352635053786165627414518)
call B58 '636363'x
say B58('61'x); say B58('626262'x)
callsay B58('636363'x); say B58('73696d706c792061206c6f6e6720737472696e67'x)
call B58 '516b6fcd0f'x
callsay B58('516b6fcd0f'x); say B58('bf4f89001e670274dd'x)
say B58('572e4794'x); say B58('ecac89cad93923c02321'x)
call B58 '572e4794'x
callsay B58 ('ecac89cad93923c0232110c8511e'x)
exit 0 do until z=0; $=substr(@, z//58*stick +1,a 1)$;fork in it, z=zwe're %all 58done. */
call B58 '10c8511e'x
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
B58: parse arg z 1 oz,,$; L1= 0; hxhex= 0; if numeric digits 500 z='' /*for hugethen nums.*/return
if z='' then return /*Is Z missing? */
if \datatype(z, 'W') | arg()>1 then hx=1do; hex= if1; hx then z= c2d(z); end /*is Z in hex ? */
if left(z, 1)==1 then L1= verify(z ., 1) - 1 /*count number of leading ones (1's (ones). */
do until z==0; $= substr(@, z//58 +1, 1)$; z= z % 58
/* 0─────────────────I─────O────────────────────l──────────────── ◄───omit.*/
@=space(" 123456789ABCDEFGH JKLMN PQRSTUVWXYZabcdefghi jkmnopqrstuvwxyz", 0)
$=
do until z=0; $=substr(@, z//58 +1, 1)$; z=z % 58
end /*until*/
if hxhex then oz= "'"c2x(oz)"'x" /*Original arg in hex? Transform Then transformit.*/
sayreturn right(oz, 60) '"───►'" left('', L1, 0)$ /*displayfor givenshowing argumentarg &and the residual. */</lang>
{{out|output|text=&nbsp; when using the default inputs:}}
return /* [↑] also prepend residual with 1's.*/</lang>
{{out|output}}
<pre>
25420294593250030202636073700053352635053786165627414518 ───► 6UwLL9Risc3QfPqBUvKofHmBQ7wMtjvM