gchq/CyberChef · warning · OperationError

Too many permutations, please reduce k^n to under 50,000.

Error message

Too many permutations, please reduce k^n to under 50,000.

What it means

Final validation in Generate De Bruijn Sequence: rejects inputs where k^n exceeds 50,000. The De Bruijn sequence length equals k^n, and the generator materializes supporting arrays sized by k*n, so this cap prevents excessive memory/CPU. It is a resource guard, not a mathematical constraint.

Source

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

        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;
            }

            a[t] = a[t - p];
            db(t + 1, p);
            for (let j = a[t - p] + 1; j < k; j++) {
                a[t] = j;

View on GitHub (pinned to 4290ea7539)

Solutions

  1. Reduce n so that Math.pow(k, n) <= 50000 (e.g. for k=9 keep n<=4; for k=2 keep n<=15).
  2. Alternatively reduce k.
  3. Compute k*n and Math.pow(k,n) before running to confirm the budget.

Example fix

// before
args = [9, 5]; // 9^5 = 59049 > 50000
// after
args = [9, 4]; // 9^4 = 6561
Defensive patterns

Strategy: validation

Validate before calling

if (Math.pow(k, n) > 50000) throw new Error(`k^n = ${Math.pow(k,n)} exceeds 50000; reduce k or n`);

Type guard

/** @param {number} k @param {number} n */
function withinBudget(k,n){return Math.pow(k,n) <= 50000;}

Prevention

When it happens

Trigger: Any (k, n) pair whose exponentiation exceeds 50,000, e.g. k=9,n=5 (59049) or k=3,n=10 (59049) or k=2,n=16 (65536).

Common situations: Pushing for maximum coverage keycodes; not realizing sequence length grows exponentially; nudge n up expecting linear cost.

Related errors


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