Published
Edited
Oct 10, 2022
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
btoa(b_s) // It matches!
Insert cell
Insert cell
Insert cell
Insert cell
btoa(atob(b62_ex_1))
Insert cell
Insert cell
getExamples(20, () => randString(4, b62_alphabet))
Insert cell
Insert cell
b62_ex_2 = "99999"
Insert cell
{
const inp = b62_ex_2;

const nums = b62_ex_2.split("").map(c => b62_alphabet.indexOf(c));

const bins = nums.map(toBinArr).map(a => a.slice(2))
return {nums, bins}

}
Insert cell
parseInt("111100", 2)
Insert cell
Insert cell
toByteStr = (a) => String.fromCharCode(...a)
Insert cell
b_s = toByteStr(b_a)
Insert cell
Insert cell

fromByteStr = (s) => s.split("").map(c => c.charCodeAt(0))
Insert cell
[fromByteStr(b_s), fromByteStr(b_s).join("") === b_a.join("")]
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
atoi = (a) => a.charCodeAt(0)
Insert cell
atob("s9Pp")
Insert cell
Insert cell
ex1 = {
let og = "+3/";
// ^ we know
return {in: og, roundtrip: btoa(atob(og))}
}
Insert cell
ex1_bytes = atob(ex1.in)
Insert cell
btoa(ex1_bytes)
Insert cell
{
let inp = ex1.in; // 18
let out = btoa(atob(ex1.in));

let inp_bs = atob(inp);
let inp_ba = fromByteStr(inp_bs); // 16 bits, we lost 2 bits


let getB64DecArray = (s) => s.split("").map(c => b64_alphabet.indexOf(c));

let b64_da_inp = getB64DecArray(inp);
let b64_da_out = getB64DecArray(out);

let inp_bits = b64_da_inp.map(c => toBinArr(c).slice(2).join(""))
let out_bits = b64_da_out.map(c => toBinArr(c).slice(2).join(""))

let enc_bits = inp_ba.map(c => toBinArr(c).join(""))




return {out, inp_bs, inp_ba, b64_da_inp, b64_da_out, inp_bits, out_bits, enc_bits};

}
Insert cell
Insert cell
Insert cell
getExamples(5, () => randb64(3))
Insert cell
// TODO: make one that pads with an A if the modulo is 1, 2, 3, and then knows to trim it on the other side.
// ^ does that work with base62?
Insert cell
Insert cell
ex2 = {
let f1 = "+";
let og = f1 + "A";
// ^ we know there are 3 characters, so 18 bits.
// we can add an "A" on there to get it to a multiple of 4, then crop it off later?
return {in: og, roundtrip: btoa(atob(og))}
}
Insert cell
Insert cell
Insert cell
Insert cell
margin = ({top: 20, right: 20, bottom: 30, left: 40})
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