// wordList (256 four-letter words)
const wordList = [
"able", "acid", "also", "apex", "aqua", "arch", "atom", "aunt", "away", "axis",
"back", "bald", "barn", "belt", "beta", "bias", "blue", "body", "brag", "brew",
"bulb", "buzz", "calm", "cash", "cats", "chef", "city", "claw", "code", "cola",
"cook", "cost", "crux", "curl", "cusp", "cyan", "dark", "data", "days", "deli",
"dice", "diet", "door", "down", "draw", "drop", "drum", "dull", "duty", "each",
"easy", "echo", "edge", "epic", "even", "exam", "exit", "eyes", "fact", "fair",
"fern", "figs", "film", "fish", "fizz", "flap", "flew", "flux", "foxy", "free",
"frog", "fuel", "fund", "gala", "game", "gear", "gems", "gift", "girl", "glow",
"good", "gray", "grim", "guru", "gush", "gyro", "half", "hang", "hard", "hawk",
"heat", "help", "high", "hill", "holy", "hope", "horn", "huts", "iced", "idea",
"idle", "inch", "inky", "into", "iris", "iron", "item", "jade", "jazz", "join",
"jolt", "jowl", "judo", "jugs", "jump", "junk", "jury", "keep", "keno", "kept",
"keys", "kick", "kiln", "king", "kite", "kiwi", "knob", "lamb", "lava", "lazy",
"leaf", "legs", "liar", "limp", "lion", "list", "logo", "loud", "love", "luau",
"luck", "lung", "main", "many", "math", "maze", "memo", "menu", "meow", "mild",
"mint", "miss", "monk", "nail", "navy", "need", "news", "next", "noon", "note",
"numb", "obey", "oboe", "omit", "onyx", "open", "oval", "owls", "paid", "part",
"peck", "play", "plus", "poem", "pool", "pose", "puff", "puma", "purr", "quad",
"quiz", "race", "ramp", "real", "redo", "rich", "road", "rock", "roof", "ruby",
"ruin", "runs", "rust", "safe", "saga", "scar", "sets", "silk", "skew", "slot",
"soap", "solo", "song", "stub", "surf", "swan", "taco", "task", "taxi", "tent",
"tied", "time", "tiny", "toil", "tomb", "toys", "trip", "tuna", "twin", "ugly",
"undo", "unit", "urge", "user", "vast", "very", "veto", "vial", "vibe", "view",
"visa", "void", "vows", "wall", "wand", "warm", "wasp", "wave", "waxy", "webs",
"what", "when", "whiz", "wolf", "work", "yank", "yawn", "yell", "yoga", "yurt",
"zaps", "zero", "zest", "zinc", "zone", "zoom"
];
// Encode String Array to Uint8Array
const enc = new TextEncoder();
const stringArray2bytes = (words) => enc.encode(words.join(""));
function generateAsciiKeyNoncePair() {
const selected = new Set();
const randomBytes = new Uint8Array(22); // Buffer for random values
crypto.getRandomValues(randomBytes);
let byteIndex = 0;
while (selected.size < 11) {
if (byteIndex >= randomBytes.length) {
crypto.getRandomValues(randomBytes);
byteIndex = 0;
}
selected.add(randomBytes[byteIndex++]);
}
const indices = Array.from(selected);
return {
keyAscii: indices.slice(0, 8).map(i => wordList[i]),
nonceAscii: indices.slice(8, 11).map(i => wordList[i])
};
}
const { keyAscii, nonceAscii } = generateAsciiKeyNoncePair();
console.log("Ascii Key:", keyAscii);
console.log("Ascii Nonce:", nonceAscii);
console.log("Ascii Key:", stringArray2bytes(keyAscii));
console.log("Ascii Nonce:", stringArray2bytes(nonceAscii));