gchq/CyberChef · error · OperationError

Exponent must be defined

Error message

Exponent must be defined

What it means

Thrown by the Modular Exponentiation operation in 'Case 3': the Base argument is supplied, the Exponent argument is blank, and the Input field is also blank — so there is no value to use as the exponent. The operation resolves a missing Exponent from the Input; if both are empty it throws at ModularExponentiation.mjs:90.

Source

Thrown at src/core/operations/ModularExponentiation.mjs:90

        // if their boxes are empty.
        let base, exp;
        if (baseParam && expParam) {
            // Case 1: base and exponent both given as parameters
            base = baseParam;
            exp  = expParam;
        } else if (!baseParam && expParam) {
            // Case 2: base missing - take from input
            base = inputVal;
            exp  = expParam;
            if (!base) {
                throw new OperationError("Base must be defined");
            }
        } else if (baseParam && !expParam) {
            // Case 3: exponent missing - take from input
            base = baseParam;
            exp  = inputVal;
            if (!exp) {
                throw new OperationError("Exponent must be defined");
            }
        } else if (!inputVal) {
            // Case 4: base and exponent both missing
            throw new OperationError("Base and Exponent must be defined");
        } else throw new OperationError("Ambiguous input: specify either Base or Exponent when using Input");

        // Parse numbers
        const baseBI = parseBigInt(base, "Base");
        const expBI  = parseBigInt(exp, "Exponent");
        const modBI  = parseBigInt(mod, "Modulus");

        // Check for invalid modulus (parseBigInt eliminates negatives)
        if (modBI === 0n) {
            throw new OperationError("Modulus must be greater than zero");
        }

        return modPow(baseBI, expBI, modBI).toString();
    }

View on GitHub (pinned to 4290ea7539)

Solutions

  1. Provide an Exponent value either in the Exponent argument or in the Input field.
  2. If using Input as the exponent, ensure the upstream step emits a value.
  3. Validate that at least one of Exponent-arg / Input is non-empty when Base is set.

Example fix

// before — exponent missing both as arg and input
modExp.run('', ['2', '15', '']);   // exp blank, input blank

// after — supply exponent via input
modExp.run('6', ['2', '15', '']);  // 2^6 mod 15
Defensive patterns

Strategy: validation

Validate before calling

// Case 3: Exponent blank, Base set -> Exponent must come from Input.
function resolveExpCase3(expArg, input) {
  const exp = (expArg ?? '').trim() || (input ?? '').trim();
  if (!exp) throw new Error('Exponent must be defined (fill Exponent arg or Input)');
  return exp;
}

Type guard

function hasExpForCase3(expArg: unknown, input: unknown): boolean {
  const e = (typeof expArg === 'string' ? expArg.trim() : '') || (typeof input === 'string' ? input.trim() : '');
  return e.length > 0;
}

Prevention

When it happens

Trigger: args: Base=<set>, Exponent='', and input='' (or whitespace). The code path at ModularExponentiation.mjs:85-91 takes exp from inputVal, then rejects an empty exponent. Triggered when the user supplies only a base and forgets the input.

Common situations: User filled the Base field, left Exponent empty intending to use Input, but also left Input empty; upstream recipe step emitted nothing; whitespace-only input.

Related errors


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