Home / Volume 1 / Chapter 06 / Code Chapter 06 of 22 Part II: The Connected World
The Secret Life of a SIM Card
Lesson & Field Guide
Interactive Lab
3 Projects
Source Code
Self-Check Quiz
3 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) · 555 bytes · SHA-256: e67133af21e5…
Standalone runnable
Dependencies: None (standard ES2022 JavaScript). Runs directly in Node.js or the isolated browser sandbox and logs output.
const transitions = {
OFF: { power: "SEARCHING" },
SEARCHING: { cell: "REGISTERING" },
REGISTERING: { accept: "READY", reject: "SEARCHING" },
READY: { dial: "RINGING" },
RINGING: { answer: "CONNECTED", cancel: "READY" },
CONNECTED: { hangup: "READY", lost: "SEARCHING" }
};
function nextState(state, event) {
return transitions[state]?.[event] ?? state;
}
let state = "OFF";
for (const event of ["power", "cell", "accept",
"dial", "answer", "hangup"]) {
state = nextState(state, event);
console.log(event, state);
} Sandboxed Output (Worker timeout: 2s, no network) Reset
block-02.js
Printed book snippet (byte-identical) · 423 bytes · SHA-256: 96faf6e965d3…
Standalone runnable
Dependencies: None (standard ES2022 JavaScript). Runs directly in Node.js or the isolated browser sandbox and logs output.
// A toy rule, NOT real SIM cryptography.
function toyResponse(challenge, secret) {
return (challenge * 7 + secret * 3) % 97;
}
function authenticate(challenge, cardSecret, homeSecret) {
const answer = toyResponse(challenge, cardSecret);
const expected = toyResponse(challenge, homeSecret);
return answer === expected;
}
console.log(authenticate(19, 23, 23)); // true
console.log(authenticate(19, 24, 23)); // false Sandboxed Output (Worker timeout: 2s, no network) Reset
block-03.js
Printed book snippet (byte-identical) · 407 bytes · SHA-256: bdefd637e195…
Standalone runnable
Dependencies: None (standard ES2022 JavaScript). Runs directly in Node.js or the isolated browser sandbox and logs output.
function signal(x, towerX) {
return -45 - 20 * Math.log10(1 + Math.abs(x-towerX));
}
function chooseCell(x, serving, margin = 3) {
const a = signal(x, 0), b = signal(x, 10);
if (serving === "A" && b > a + margin) return "B";
if (serving === "B" && a > b + margin) return "A";
return serving;
}
let cell = "A";
for (let x = 0; x <= 10; x++) {
cell = chooseCell(x, cell);
console.log(x, cell);
} Sandboxed Output (Worker timeout: 2s, no network) Reset
← Ch. 05: Recovering the Impossible
Ch. 07: The Digital Detective →