gchq/CyberChef · error · OperationError
Error: Radix argument must be divisible by 2
Error message
Error: Radix argument must be divisible by 2
What it means
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.
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.
Example fix
// before luhn.run(input, [11]); // odd -> rejected // after luhn.run(input, [10]); // even, classic Luhn
Defensive patterns
Strategy: validation
Validate before calling
function evenRadix(r) {
return Number.isInteger(r) && r >= 2 && r <= 36 && r % 2 === 0;
}
if (!evenRadix(radix)) throw new Error('Radix must be even, 2..36'); Type guard
function isEvenRadix(v: unknown): v is number {
return typeof v === 'number' && Number.isInteger(v) && v >= 2 && v <= 36 && v % 2 === 0;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Character: is not valid in radix .
- Error: Radix argument must be between 2 and 36
- Error: Base argument must be between 2 and 36
- Invalid custom CRC arguments
- Unknown checksum algorithm
AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13).
Data as JSON: /api/errors/6e32d0d232c359ed.
Report an issue: GitHub.
Appendix: source
Thrown at src/core/operations/LuhnChecksum.mjs:81
}, 0) % radix; // Use radix as the modulus base
}
/**
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
if (!input) return "";
const radix = args[0];
if (radix < 2 || radix > 36) {
throw new OperationError("Error: Radix argument must be between 2 and 36");
}
if (radix % 2 !== 0) {
throw new OperationError("Error: Radix argument must be divisible by 2");
}
const checkSum = this.checksum(input, radix).toString(radix);
let checkDigit = this.checksum(input + "0", radix);
checkDigit = checkDigit === 0 ? 0 : (radix - checkDigit);
checkDigit = checkDigit.toString(radix);
return `Checksum: ${checkSum}
Checkdigit: ${checkDigit}
Luhn Validated String: ${input + "" + checkDigit}`;
}
}
export default LuhnChecksum;
View on GitHub (pinned to 4290ea7539)