gchq/CyberChef · warning · OperationError

Invalid key length, required to be at least 2.

Error message

Invalid key length, required to be at least 2.

What it means

Fourth validation in Generate De Bruijn Sequence: requires key length `n` to be at least 2. A De Bruijn sequence of subsequence length 1 is trivial and excluded by design; the generator also indexes arrays based on n positions.

Source

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

     * @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) {
            if (t > n) {
                if (n % p !== 0) return;
                for (let j = 1; j <= p; j++) {
                    sequence.push(a[j]);
                }
                return;
            }

View on GitHub (pinned to 4290ea7539)

Solutions

  1. Set Key length (n) to an integer >= 2.
  2. Keep n large enough that the generated sequence is meaningful for your use case.

Example fix

// before
args = [2, 1];
// after
args = [2, 3];
Defensive patterns

Strategy: validation

Validate before calling

if (!Number.isInteger(n) || n < 2) throw new Error("Key length n must be an integer >= 2");

Type guard

/** @param {number} n */
function isValidKeyLength(n){return Number.isInteger(n) && n >= 2;}

Prevention

When it happens

Trigger: Setting Key length (n) to 0, 1, or a negative number.

Common situations: Misreading n as alphabet size; testing edge cases with n=1.

Related errors


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