Published
Edited
Sep 16, 2021
Fork of CRC-32
Insert cell
Insert cell
Insert cell
blake = require('https://bundle.run/blakejs@1.1.1')
Insert cell
Insert cell
// - text - a string or a byte array
// - bitlen - bit length, must be multiple of 8
function blake2s(text, bitlen = 256) {
if (bitlen % 8 != 0) {
throw Error("`bitlen` must be multiple of 8");
}
return blake.blake2sHex(text, "", bitlen / 8);
}
Insert cell
function blake2b(text, bitlen = 256) {
if (bitlen % 8 != 0) {
throw Error("`bitlen` must be multiple of 8");
}
return blake.blake2bHex(text, "", bitlen / 8);
}
Insert cell
// Converts a hex string to a binary string
function hex2bin(hexdigest) {
const hexlen = hexdigest.length;
if (hexlen % 2 != 0) {
throw Error("`hexdigest` length must be multiply of 2");
}
let result = "";
for (let i = 0; i < hexlen; i += 2) {
let int = parseInt(hexdigest.substr(i, 2), 16);
result += String.fromCharCode(parseInt(hexdigest.substr(i, 2), 16));
}
return result;
}
Insert cell
// Converts a hex digest to a binary, and returns the binary as a Base64 string
function hex2base64(hexdigest) {
return btoa(hex2bin(hexdigest));
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
hex = blake2s(demo, bitlen)
Insert cell
hex2bin(hex)
Insert cell
hex2base64(hex)
Insert cell
Insert cell
Insert cell
blake2s("", 128)
Insert cell
Insert cell
blake2s("", 256)
Insert cell
Insert cell
hex2base64(blake2s("", 256))
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more