{"record":{"id":"f993f26f7781a18a","repo":"gchq/CyberChef","slug":"invalid-alphabet-size-required-to-be-between-2-an","errorCode":null,"errorMessage":"Invalid alphabet size, required to be between 2 and 9 (inclusive).","messagePattern":"Invalid alphabet size, required to be between 2 and 9 \\(inclusive\\)\\.","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"warning","filePath":"src/core/operations/GenerateDeBruijnSequence.mjs","lineNumber":50,"sourceCode":"            },\n            {\n                name: \"Key length (n)\",\n                type: \"number\",\n                value: 3\n            }\n        ];\n    }\n\n    /**\n     * @param {string} input\n     * @param {Object[]} args\n     * @returns {string}\n     */\n    run(input, args) {\n        const [k, n] = args;\n\n        if (k < 2 || k > 9) {\n            throw new OperationError(\"Invalid alphabet size, required to be between 2 and 9 (inclusive).\");\n        }\n\n        if (!Number.isInteger(k)) {\n            throw new OperationError(\"Invalid alphabet size, required to be integer.\");\n        }\n\n        if (!Number.isInteger(n)) {\n            throw new OperationError(\"Invalid key length, required to be integer.\");\n        }\n\n        if (n < 2) {\n            throw new OperationError(\"Invalid key length, required to be at least 2.\");\n        }\n\n        if (Math.pow(k, n) > 50000) {\n            throw new OperationError(\"Too many permutations, please reduce k^n to under 50,000.\");\n        }\n","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/GenerateDeBruijnSequence.mjs#L32-L68","documentation":"First validation in Generate De Bruijn Sequence: rejects alphabet size `k` outside 2..9 inclusive. The De Bruijn generator allocates an array of size k*n and branches over k symbols, so the bound keeps memory and runtime sane. Note the ordering quirk: this range check runs BEFORE the integer check, so a non-integer k that is also out of range (e.g. 1.5 or 10.5) hits this message rather than the integer one.","triggerScenarios":"Setting Alphabet size (k) to 1, 0, a negative, 10+, or any non-integer value that falls outside 2..9 (e.g. k=10 or k=1.5 both fail here).","commonSituations":"Mistaking k for key length; entering a large alphabet assuming the op supports arbitrary bases; passing a float because the number field accepted decimals.","solutions":["Set Alphabet size (k) to an integer between 2 and 9 inclusive.","If you need a larger alphabet, reduce n so k^n stays under 50,000, but k itself cannot exceed 9 in this op.","Enter whole numbers only in the k field."],"exampleFix":"// before\nargs = [10, 3];\n// after\nargs = [9, 3];","handlingStrategy":"validation","validationCode":"if (!Number.isInteger(k) || k < 2 || k > 9) throw new Error(\"Alphabet size k must be an integer in [2, 9]\");","typeGuard":"/** @param {number} k */\nfunction isValidAlphabetSize(k){return Number.isInteger(k) && k >= 2 && k <= 9;}","tryCatchPattern":null,"preventionTips":["Treat k as a small integer alphabet cardinality (2..9).","Validate both integer-ness and range before calling the op.","Remember the op caps k at 9 regardless of n budget."],"tags":["combinatorics","de-bruijn","argument-validation","bounds"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}