Bitcoin/address validation: Difference between revisions
Content deleted Content added
→{{header|Ruby}}: Add Rust implementation |
→{{header|zkl}}: update |
||
Line 1,316:
=={{header|zkl}}==
Uses shared library zklMsgHash.
<lang zkl>var [const] MsgHash=Import("zklMsgHash"); // SHA-256, etc
const symbols="123456789" // 58 characters: no cap i,o; ell, zero
"ABCDEFGHJKLMNPQRSTUVWXYZ"
Line 1,322:
fcn unbase58(str){ // --> Data (byte bucket)
out:=Data(
str.pump(Void,symbols.index,'wrap(n){ //
[24..0,-1].reduce('wrap(c,idx){
c+=58*out[idx]; // throws if not enough data
out[idx]=c;
c/256; // should be zero when done
},n) : if(_) throw(Exception.ValueError("address too long"));
});
Line 1,334:
fcn coinValide(addr){
reg dec,chkSum;
// hash twice, once each time --> binary hash (instead of hex string)▼
chkSum=dec[-4,*]; dec.del(21,*);
(2).reduce(MsgHash.SHA256.fp1(1,dec),dec); // dec is i/o buffer
dec[0,4]==chkSum;
}</lang>
<lang zkl>T("1AGNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW62i","1Q1pE5vPGEEMqRcVRMbtBK842Y6Pzo6nK9",
|