Shift (Ch. 11 Example 1)
File: block-01.js (byte-identical) · 316 bytes · SHA-256: 1eacac1f8f5a…
Caesar cipher Standalone runnable
Dependencies: None (standard ES2022 JavaScript). Runs directly in Node.js or the isolated Web Worker sandbox and prints console output.
function shift(text, key) {
return text.replace(/[A-Za-z]/g, letter => {
const base = letter >= "a" ? 97 : 65;
const x = letter.charCodeAt(0) - base;
const y = ((x + key) % 26 + 26) % 26;
return String.fromCharCode(base + y);
});
}
console.log(shift("HELLO", 3));
console.log(shift("KHOOR", -3)); Sandboxed Output (Worker timeout: 2s, no network) Reset
Count Letters (Ch. 11 Example 2)
File: block-02.js (byte-identical) · 287 bytes · SHA-256: 4a121dd12ee1…
Caesar cipher Standalone runnable
Dependencies: None (standard ES2022 JavaScript). Runs directly in Node.js or the isolated Web Worker sandbox and prints console output.
function countLetters(text) {
const counts = {};
for (const ch of text.toUpperCase()) {
if (ch >= "A" && ch <= "Z") {
counts[ch] = (counts[ch] || 0) + 1;
}
}
return Object.entries(counts)
.sort((a, b) => b[1] - a[1]);
}
console.log(countLetters("XQ XQ XQ AB")); Sandboxed Output (Worker timeout: 2s, no network) Reset
Mod Pow (Ch. 11 Example 3)
File: block-03.js (byte-identical) · 391 bytes · SHA-256: 5bf2cf630855…
Caesar cipher Standalone runnable
Dependencies: None (standard ES2022 JavaScript). Runs directly in Node.js or the isolated Web Worker sandbox and prints console output.
function modPow(base, exp, mod) {
let result = 1n;
base %= mod;
while (exp > 0n) {
if (exp % 2n === 1n) {
result = (result * base) % mod;
}
base = (base * base) % mod;
exp /= 2n;
}
return result;
}
const p = 23n, g = 5n;
const a = 6n, b = 15n;
const A = modPow(g, a, p);
const B = modPow(g, b, p);
console.log(A, B);
console.log(modPow(B,a,p), modPow(A,b,p)); Sandboxed Output (Worker timeout: 2s, no network) Reset