{"record":{"id":"6e32d0d232c359ed","repo":"gchq/CyberChef","slug":"error-radix-argument-must-be-divisible-by-2","errorCode":null,"errorMessage":"Error: Radix argument must be divisible by 2","messagePattern":"Error: Radix argument must be divisible by 2","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/LuhnChecksum.mjs","lineNumber":81,"sourceCode":"        }, 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\nexport default LuhnChecksum;\n","sourceCodeStart":63,"sourceCodeEnd":97,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/LuhnChecksum.mjs#L63-L97","documentation":"Thrown by the Luhn Checksum operation when the 'Radix' argument (args[0]) is within 2–36 but not divisible by 2. The Luhn mod-N algorithm requires an even base (the 'double and sum digits' step assumes base N splits cleanly), so run() rejects odd radices at LuhnChecksum.mjs:81 with an OperationError. This check runs after the range check (line 76), so odd values like 3, 5, …, 35 are the only ones that reach it.","triggerScenarios":"Setting Radix to an odd integer between 3 and 35 inclusive — e.g. 3, 5, 7, 10 is fine, but 11 or 13 triggers it. Raised at LuhnChecksum.mjs:80-82.","commonSituations":"Choosing radix=10 (valid) but accidentally typing an odd value like 11; assuming any base 2–36 works; copying a recipe that used an odd base for a non-Luhn checksum.","solutions":["Set Radix to an even integer between 2 and 36 (2, 4, 6, …, 36). 10 is the classic Luhn base.","Validate that radix % 2 === 0 before running.","If you genuinely need an odd base, Luhn mod-N is the wrong algorithm — pick a different checksum operation."],"exampleFix":"// before\nluhn.run(input, [11]);   // odd -> rejected\n\n// after\nluhn.run(input, [10]);   // even, classic Luhn","handlingStrategy":"validation","validationCode":"function evenRadix(r) {\n  return Number.isInteger(r) && r >= 2 && r <= 36 && r % 2 === 0;\n}\nif (!evenRadix(radix)) throw new Error('Radix must be even, 2..36');","typeGuard":"function isEvenRadix(v: unknown): v is number {\n  return typeof v === 'number' && Number.isInteger(v) && v >= 2 && v <= 36 && v % 2 === 0;\n}","tryCatchPattern":null,"preventionTips":["Pick from the valid even set {2,4,6,...,36}; avoid odd values.","Validate radix % 2 === 0 alongside the 2..36 range in one guard.","Use 10 (classic) or 36 (alphanumeric) as safe defaults."],"tags":["luhn","checksum","validation","radix","argument-constraint"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}