Chapter 14 of 22 Part III: Trust, Cryptography & Security

The Invisible Digital Enemy

6 Verified Book Snippets

Every .js file below is byte-identical (SHA-256 verified) to the printed code in Volume 1. Runnable blocks execute inside an isolated sandboxed iframe and Web Worker with a 2-second timeout and zero network access.

Download Chapter ZIP

block-01.js

Printed book snippet (byte-identical) · 313 bytes · SHA-256: 7aeaa3701a00…
Standalone runnable

Dependencies: None (standard ES2022 JavaScript). Defines pure JavaScript functions/data; runs cleanly in the sandbox (add a console.log call in your own test to inspect return values).

function step(states, links, blocked = []) {
  const next = [...states];
  for (const [a, b] of links) {
    if (blocked.includes(a) || blocked.includes(b)) continue;
    if (states[a] === 'I' && states[b] === 'S') next[b] = 'I';
    if (states[b] === 'I' && states[a] === 'S') next[a] = 'I';
  }
  return next;
}
Download .js

block-02.js

Printed book snippet (byte-identical) · 201 bytes · SHA-256: f81e215bd595…
Standalone runnable

Dependencies: None (standard ES2022 JavaScript). Runs directly in Node.js or the isolated browser sandbox and logs output.

const links = [[0,1],[1,2],[1,3],[3,4],[4,5]];
let nodes = ['I','S','S','S','S','S'];
nodes = step(nodes, links);
console.log(nodes.join(' '));
nodes = step(nodes, links);
console.log(nodes.join(' '));
Download .js

block-03.js

Printed book snippet (byte-identical) · 85 bytes · SHA-256: 77b314cabcfb…
Standalone runnable

Dependencies: None (standard ES2022 JavaScript). Defines pure JavaScript functions/data; runs cleanly in the sandbox (add a console.log call in your own test to inspect return values).

function scan(label) {
  return label.includes('RED_STAR') ? 'Review' : 'No match';
}
Download .js

block-04.js

Printed book snippet (byte-identical) · 147 bytes · SHA-256: a0e3ef977dc6…
Standalone runnable

Dependencies: None (standard ES2022 JavaScript). Runs directly in Node.js or the isolated browser sandbox and logs output.

const labels = ['BLUE_CIRCLE', 'RED_STAR',
  'RED_STAR_ART', 'YELLOW_TRIANGLE'];
for (const label of labels) {
  console.log(label, scan(label));
}
Download .js

block-05.js

Printed book snippet (byte-identical) · 117 bytes · SHA-256: e57c32c43eaa…
Standalone runnable

Dependencies: None (standard ES2022 JavaScript). Defines pure JavaScript functions/data; runs cleanly in the sandbox (add a console.log call in your own test to inspect return values).

function review(events) {
  return events.filter(e => e.kind === 'warning' && !e.reviewed)
    .map(e => e.device);
}
Download .js

block-06.js

Printed book snippet (byte-identical) · 227 bytes · SHA-256: c29dedc55c65…
Standalone runnable

Dependencies: None (standard ES2022 JavaScript). Runs directly in Node.js or the isolated browser sandbox and logs output.

const events = [
  {device:'A',kind:'warning',reviewed:false},
  {device:'B',kind:'info',reviewed:false},
  {device:'C',kind:'warning',reviewed:true},
  {device:'D',kind:'warning',reviewed:false}
];
console.log(review(events));
Download .js