gchq/CyberChef · warning · OperationError

Invalid alphabet size, required to be integer.

Error message

Invalid alphabet size, required to be integer.

What it means

Second validation in Generate De Bruijn Sequence: requires `k` to be an integer. It runs only after the 2..9 range check passes, so it catches fractional values that nonetheless fell inside the range (e.g. k=2.5, k=8.1). Number.isInteger rejects NaN, Infinity, and any non-whole float.

Source

Thrown at src/core/operations/GenerateDeBruijnSequence.mjs:54

                value: 3
            }
        ];
    }

    /**
     * @param {string} input
     * @param {Object[]} args
     * @returns {string}
     */
    run(input, args) {
        const [k, n] = args;

        if (k < 2 || k > 9) {
            throw new OperationError("Invalid alphabet size, required to be between 2 and 9 (inclusive).");
        }

        if (!Number.isInteger(k)) {
            throw new OperationError("Invalid alphabet size, required to be integer.");
        }

        if (!Number.isInteger(n)) {
            throw new OperationError("Invalid key length, required to be integer.");
        }

        if (n < 2) {
            throw new OperationError("Invalid key length, required to be at least 2.");
        }

        if (Math.pow(k, n) > 50000) {
            throw new OperationError("Too many permutations, please reduce k^n to under 50,000.");
        }

        const a = new Array(k * n).fill(0);
        const sequence = [];

        (function db(t = 1, p = 1) {

View on GitHub (pinned to 4290ea7539)

Solutions

  1. Round k to a whole number before running.
  2. Enter only integers in the Alphabet size field.
  3. If computing k, wrap with Math.round or Math.floor.

Example fix

// before
args = [2.5, 4];
// after
args = [2, 4]; // or Math.round(2.5) === 3
Defensive patterns

Strategy: validation

Validate before calling

if (!Number.isInteger(k)) throw new Error("Alphabet size k must be an integer");

Type guard

function isInt(k){return Number.isInteger(k);}

Prevention

When it happens

Trigger: Entering a decimal alphabet size like 2.5 or 7.3; the value slipping in as a float via a programmatic recipe even though the field is numeric.

Common situations: Number field allowing decimals; scripting the op with a computed float that wasn't rounded.

Related errors


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