Chapter 14 of 22 Part III: Cybersecurity and Privacy

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

Step (Ch. 14 Example 1)

File: block-01.js (byte-identical) · 313 bytes · SHA-256: 7aeaa3701a00…
defensive security Standalone runnable

Dependencies: None (standard ES2022 JavaScript). Defines pure JavaScript functions or data; runs cleanly in the sandbox (call console.log in a test harness to inspect 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

Links — The Invisible Digital Enemy (Example 2)

File: block-02.js (byte-identical) · 201 bytes · SHA-256: f81e215bd595…
defensive security Standalone runnable

Dependencies: None (standard ES2022 JavaScript). Runs directly in Node.js or the isolated Web Worker sandbox and prints console 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

Scan (Ch. 14 Example 3)

File: block-03.js (byte-identical) · 85 bytes · SHA-256: 77b314cabcfb…
defensive security Standalone runnable

Dependencies: None (standard ES2022 JavaScript). Defines pure JavaScript functions or data; runs cleanly in the sandbox (call console.log in a test harness to inspect values).

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

Labels — The Invisible Digital Enemy (Example 4)

File: block-04.js (byte-identical) · 147 bytes · SHA-256: a0e3ef977dc6…
defensive security Standalone runnable

Dependencies: None (standard ES2022 JavaScript). Runs directly in Node.js or the isolated Web Worker sandbox and prints console output.

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

Review (Ch. 14 Example 5)

File: block-05.js (byte-identical) · 117 bytes · SHA-256: e57c32c43eaa…
defensive security Standalone runnable

Dependencies: None (standard ES2022 JavaScript). Defines pure JavaScript functions or data; runs cleanly in the sandbox (call console.log in a test harness to inspect values).

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

Events — The Invisible Digital Enemy (Example 6)

File: block-06.js (byte-identical) · 227 bytes · SHA-256: c29dedc55c65…
defensive security Standalone runnable

Dependencies: None (standard ES2022 JavaScript). Runs directly in Node.js or the isolated Web Worker sandbox and prints console 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