{"record":{"id":"fa9868eae757930d","repo":"gchq/CyberChef","slug":"error-base-argument-must-be-between-2-and-36","errorCode":null,"errorMessage":"Error: Base argument must be between 2 and 36","messagePattern":"Error: Base argument must be between 2 and 36","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/FromCharcode.mjs","lineNumber":58,"sourceCode":"            }\n        ];\n    }\n\n    /**\n     * @param {string} input\n     * @param {Object[]} args\n     * @returns {ArrayBuffer}\n     *\n     * @throws {OperationError} if base out of range\n     */\n    run(input, args) {\n        const delim = Utils.charRep(args[0] || \"Space\"),\n            base = args[1];\n        let bites = input.split(delim),\n            i = 0;\n\n        if (base < 2 || base > 36) {\n            throw new OperationError(\"Error: Base argument must be between 2 and 36\");\n        }\n\n        if (input.length === 0) {\n            return new ArrayBuffer;\n        }\n\n        if (base !== 16 && isWorkerEnvironment()) self.setOption(\"attemptHighlight\", false);\n\n        // Split into groups of 2 if the whole string is concatenated and\n        // too long to be a single character\n        if (bites.length === 1 && input.length > 17) {\n            bites = [];\n            for (i = 0; i < input.length; i += 2) {\n                bites.push(input.slice(i, i+2));\n            }\n        }\n\n        let latin1 = \"\";","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/FromCharcode.mjs#L40-L76","documentation":"Thrown by From Charcode when the Base argument is outside 2-36. The operation uses parseInt(bites[i], base), which only accepts bases in that range. The check runs before parsing any character codes, so it fires regardless of input content. This mirrors the From Base radix constraint.","triggerScenarios":"Setting the Base arg below 2 or above 36; passing 0, 1, or 64; a recipe configured for base-64 charcodes (which is not supported here).","commonSituations":"Confusing charcode base with Base64 encoding; typo in the Base field; programmatic recipe with an unvalidated base value.","solutions":["Set the Base arg to a supported value (commonly 16 for hex, 10 for decimal).","For Base64 text, use the From Base64 operation instead.","Validate the base in calling code before invoking."],"exampleFix":"// before: base 64 (not supported)\nfromCharcode.run(input, ['Space', 64]) // throws\n// after: base 16 for hex charcodes\nfromCharcode.run(input, ['Space', 16])","handlingStrategy":"validation","validationCode":"const base = args[1];\nif (base < 2 || base > 36) {\n  // clamp/fix the base; do not call fromCharcode.run()\n}","typeGuard":"function isValidCharcodeBase(b) {\n  return Number.isInteger(b) && b >= 2 && b <= 36;\n}","tryCatchPattern":"try {\n  fromCharcode.run(input, args);\n} catch (e) {\n  if (e.type === 'OperationError' && /Base argument must be between/.test(e.message)) {\n    // set Base to 16 (hex) or 10 (decimal); use From Base64 for base-64\n  } else throw e;\n}","preventionTips":["Constrain the Base UI input to 2-36.","Use From Base64 for Base64-encoded text, not this op.","Validate programmatically-supplied base values."],"tags":["charcode","radix","argument-validation","numeric"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}