Public
Edited
Oct 28, 2022
Insert cell
Insert cell
inputs = {
const raw = await FileAttachment("8.txt").text();
const lines = raw.split("\n");

const bytes = lines.map(lib.fromHex);

return {
raw,
lines,
bytes
}
}
Insert cell
freqList = (arr) => {
const freqs = lib.makeFreqs(arr);

return Object.keys(freqs).map(k => {return {'freq': freqs[k], key: k}}).sort((a, b)=> b.freq - a.freq)
}
Insert cell
allFreqs = inputs.bytes.map((bs, i) => {
const fl = freqList(bs);
return fl.map(f => ({...f, idx: i}))
}).flat()
Insert cell
Plot.plot({
width: width,
style: {
background: "black",
color: "white",
},
facet: {
data: allFreqs,
y: "idx"
},
color: {type: 'linear',
scheme: 'inferno',
//symmetric: false,
// reverse: true,
domain:[1,9],
legend: true,
pivot: 6,
//range:[-5, 0,5]
},
x: {label: null, axis: null},
// color: {type: 'diverging',
// domain:[2,5],
// //range:[0,1]
// },
marks: [
Plot.cellX(allFreqs, {x: d => parseInt(d.key), fill: 'freq'})
],
})

Insert cell
{
const d1 = allFreqs.filter(d => (d.idx == 131 || d.idx == 132));


return Plot.plot({
width: width,
facet: {
data: d1 ,
y: "idx"
},
x: {label: null, axis: null},
color: {type: 'diverging',
scheme: 'blues',
//symmetric: false,
reverse: false,
domain:[1,9],
legend: true,
pivot: 6,
//range:[-5, 0,5]
},
marks: [
Plot.cellX(d1
, {x: d => parseInt(d.key), fill: 'freq'})
],
})

}

Insert cell
Plot.plot({
width: width,
marks: [
Plot.barY(allFreqs.filter(d => d.idx === 132), {x: 'key', y: 'freq'})
],
})
Insert cell
lib.tob64(inputs.bytes[132])
Insert cell
chunkFreqs = inputs.bytes.map((b, i) => {
const chunks = lib.chunkArr(b, 16).map(lib.toHex)

return freqList(chunks).map(c => ({...c, idx: i}))
}).flat()
Insert cell
mostFreq = chunkFreqs.filter(c => c.freq > 1)
Insert cell
import {decryptAes128Ebc} from "e06c7d85a5552a65"
Insert cell
import {lib} from "@pcarleton/cryptopals-helpers"
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