{"record":{"id":"6a386992e9ce1d38","repo":"gchq/CyberChef","slug":"invalid-key-length-required-to-be-integer","errorCode":null,"errorMessage":"Invalid key length, required to be integer.","messagePattern":"Invalid key length, required to be integer\\.","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"warning","filePath":"src/core/operations/GenerateDeBruijnSequence.mjs","lineNumber":58,"sourceCode":"\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\n        const a = new Array(k * n).fill(0);\n        const sequence = [];\n\n        (function db(t = 1, p = 1) {\n            if (t > n) {\n                if (n % p !== 0) return;\n                for (let j = 1; j <= p; j++) {\n                    sequence.push(a[j]);","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/GenerateDeBruijnSequence.mjs#L40-L76","documentation":"Third validation in Generate De Bruijn Sequence: requires key length `n` to be an integer. Catches fractional n (e.g. 3.5) since the recursion and array sizing assume a whole count of symbol positions. NaN/Infinity are also rejected.","triggerScenarios":"Entering a decimal key length like 3.5; a computed float passed programmatically without rounding.","commonSituations":"Number field accepting decimals; scripting with an unrounded computed value.","solutions":["Round n to a whole number.","Enter only integers in the Key length field.","Wrap computed n with Math.round/Math.floor."],"exampleFix":"// before\nargs = [2, 3.5];\n// after\nargs = [2, 4];","handlingStrategy":"validation","validationCode":"if (!Number.isInteger(n)) throw new Error(\"Key length n must be an integer\");","typeGuard":"function isInt(n){return Number.isInteger(n);}","tryCatchPattern":null,"preventionTips":["Round n before passing.","Enter whole numbers only in the key length field."],"tags":["combinatorics","de-bruijn","argument-validation","type"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}