Public
Edited
Oct 13, 2022
Importers
Insert cell
Insert cell
Insert cell
chunkArr = (arr, chunkSize) => {
let chunks = [];
for (let i = 0; i < arr.length; i += chunkSize) {
chunks.push(arr.slice(i, i+chunkSize));
}
return chunks;
}
Insert cell
chunkArr([1, 2, 3, 4, 5, 6], 2)
Insert cell
encryptArrs = (iarr, karr) => {
let chunks = chunkArr(iarr, karr.length);
let r = [];
for (let ch of chunks) {
for (let i = 0; i < ch.length; i += 1) {
r.push(ch[i] ^ karr[i]);
}
}

return r
}
Insert cell
input_text = `Burning 'em, if you ain't quick and nimble
I go crazy when I hear a cymbal`
Insert cell
answer = lib.toHex(encryptArrs(input_text.split("").map(lib.atoi), "ICE".split("").map(lib.atoi)))
Insert cell
expected = `0b3637272a2b2e63622c2e69692a23693a2a3c6324202d623d63343c2a26226324272765272a282b2f20430a652e2c652a3124333a653e2b2027630c692b20283165286326302e27282f`
Insert cell
expected == answer
Insert cell
count1s = (x) => {
return lib.toBinArr(x).reduce((acc, x) => acc + x, 0);
}
Insert cell
count1s(3)
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