Chapter 13 of 22Part III: Trust, Cryptography & Security
The Digital Fingerprint
5 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.
Printed book snippet (byte-identical) · 431 bytes · SHA-256: 58d07c8719c9…
Requires HTTPS Web Crypto
Dependencies: Browser Web Crypto API (HTTPS or localhost secure context). Uses window.crypto.subtle; test inside the chapter Interactive Lab over HTTPS or localhost.
const bytes = s => new TextEncoder().encode(s);
const hex = b => Array.from(new Uint8Array(b),
n => n.toString(16).padStart(2, '0')).join('');
async function hash(text) {
return hex(await crypto.subtle.digest('SHA-256', bytes(text)));
}
function changedBits(a, b) {
let n = 0;
for (let i = 0; i < a.length; i++) {
let x = parseInt(a[i], 16) ^ parseInt(b[i], 16);
while (x) { n += x & 1; x >>= 1; }
}
return n;
}
Printed book snippet (byte-identical) · 396 bytes · SHA-256: 3ed10e871304…
Requires HTTPS Web Crypto
Dependencies: Browser Web Crypto API (HTTPS or localhost secure context). Uses window.crypto.subtle; test inside the chapter Interactive Lab over HTTPS or localhost.
Printed book snippet (byte-identical) · 585 bytes · SHA-256: a65fadde36a1…
Requires HTTPS Web Crypto
Dependencies: Browser Web Crypto API (HTTPS or localhost secure context). Uses window.crypto.subtle; test inside the chapter Interactive Lab over HTTPS or localhost.