gchq/CyberChef · error · OperationError

Error: Base argument must be between 2 and 36

Error message

Error: Base argument must be between 2 and 36

What it means

To Charcode converts characters to their numeric code points in a chosen base, but JavaScript's number.toString(radix) only accepts radix 2-36. The guard rejects any base outside that inclusive range before the conversion loop.

Source

Thrown at src/core/operations/ToCharcode.mjs:59

        ];
    }

    /**
     * @param {string} input
     * @param {Object[]} args
     * @returns {string}
     *
     * @throws {OperationError} if base argument out of range
     */
    run(input, args) {
        const delim = Utils.charRep(args[0] || "Space"),
            base = args[1];
        let output = "",
            padding,
            ordinal;

        if (base < 2 || base > 36) {
            throw new OperationError("Error: Base argument must be between 2 and 36");
        }

        const charcode = Utils.strToCharcode(input);
        for (let i = 0; i < charcode.length; i++) {
            ordinal = charcode[i];

            if (base === 16) {
                if (ordinal < 256) padding = 2;
                else if (ordinal < 65536) padding = 4;
                else if (ordinal < 16777216) padding = 6;
                else if (ordinal < 4294967296) padding = 8;
                else padding = 2;

                if (padding > 2 && isWorkerEnvironment()) self.setOption("attemptHighlight", false);

                output += Utils.hex(ordinal, padding) + delim;
            } else {
                if (isWorkerEnvironment()) self.setOption("attemptHighlight", false);

View on GitHub (pinned to 4290ea7539)

Solutions

  1. Set the Base argument to a value between 2 and 36 inclusive (16 for hex, 2 for binary, 8 for octal).
  2. Use the dedicated 'To Base64' operation for Base64 encoding instead.
  3. Confirm the argument metadata range matches the intended base.

Example fix

// before: args[1] (Base) = 64  -> throws
// after:  args[1] (Base) = 16  -> outputs hex char codes
Defensive patterns

Strategy: validation

Validate before calling

const base = args[1];
if (!(Number.isInteger(base) && base >= 2 && base <= 36)) {
  throw new Error("Base must be an integer between 2 and 36");
}

Type guard

const isValidRadix = b => Number.isInteger(b) && b >= 2 && b <= 36;

Try / catch

try { toCharcode(input, [delim, base]); }
catch (e) { if (/Base argument/.test(e.message)) { base = 16; } else throw e; }

Prevention

When it happens

Trigger: Setting the Base argument below 2 or above 36 (e.g. 1, 0, 64, or 100).

Common situations: Attempting Base64 via this op (Base64 is a separate operation); mistyping the base; defaulting an unset field to an out-of-range value.

Related errors


AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13). Data as JSON: /api/errors/2d1f3c57267e85fe. Report an issue: GitHub.