{"record":{"id":"df87d42ca306a6c3","repo":"gchq/CyberChef","slug":"error-radix-argument-must-be-between-2-and-36-df87d4","errorCode":null,"errorMessage":"Error: Radix argument must be between 2 and 36","messagePattern":"Error: Radix argument must be between 2 and 36","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/LuhnChecksum.mjs","lineNumber":77,"sourceCode":"            }\n\n            even = !even;\n            return acc + temp;\n        }, 0) % radix; // Use radix as the modulus base\n    }\n\n    /**\n     * @param {string} input\n     * @param {Object[]} args\n     * @returns {string}\n     */\n    run(input, args) {\n        if (!input) return \"\";\n\n        const radix = args[0];\n\n        if (radix < 2 || radix > 36) {\n            throw new OperationError(\"Error: Radix argument must be between 2 and 36\");\n        }\n\n        if (radix % 2 !== 0) {\n            throw new OperationError(\"Error: Radix argument must be divisible by 2\");\n        }\n\n        const checkSum = this.checksum(input, radix).toString(radix);\n        let checkDigit = this.checksum(input + \"0\", radix);\n        checkDigit = checkDigit === 0 ? 0 : (radix - checkDigit);\n        checkDigit = checkDigit.toString(radix);\n\n        return `Checksum: ${checkSum}\nCheckdigit: ${checkDigit}\nLuhn Validated String: ${input + \"\" + checkDigit}`;\n    }\n\n}\n","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/LuhnChecksum.mjs#L59-L95","documentation":"Thrown by the Luhn Checksum operation when the 'Radix' argument (args[0]) is outside the inclusive range 2–36. JavaScript's parseInt only supports radix 2–36, and the Luhn mod-N algorithm needs at least base 2, so run() rejects any other value at LuhnChecksum.mjs:77 with an OperationError. This check runs before any input is processed.","triggerScenarios":"Setting the Radix argument to a number less than 2 or greater than 36 — e.g. 0, 1, 37, 64, or a negative value. Triggered at LuhnChecksum.mjs:76-78 before checksum() is called.","commonSituations":"Default value edited to an out-of-range number; a recipe JSON carrying a stale/invalid radix; confusing the radix with a modulo or checksum length; passing a base-64 expectation (not supported — max is 36).","solutions":["Set Radix to an even integer between 2 and 36 inclusive (10 for classic Luhn, 36 for full alphanumeric).","If loading a recipe, clamp/validate the radix field before running.","For bases above 36, use a different operation — Luhn Checksum cannot represent them."],"exampleFix":"// before\nluhn.run(input, [64]);   // out of range\n\n// after\nluhn.run(input, [36]);   // valid even radix within 2..36","handlingStrategy":"validation","validationCode":"function validLuhnRadix(r) {\n  return Number.isInteger(r) && r >= 2 && r <= 36 && r % 2 === 0;\n}\nif (!validLuhnRadix(radix)) {\n  throw new Error('Radix must be an even integer between 2 and 36');\n}","typeGuard":"function isLuhnRadix(v: unknown): v is number {\n  return typeof v === 'number' && Number.isInteger(v) && v >= 2 && v <= 36 && v % 2 === 0;\n}","tryCatchPattern":null,"preventionTips":["Clamp/validate radix at recipe build time.","Default to 10 for numeric Luhn or 36 for alphanumeric.","Reject odd or out-of-range values before invoking the op."],"tags":["luhn","checksum","validation","radix","argument-range"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}