gchq/CyberChef · error · OperationError
Base must be defined
Error message
Base must be defined
What it means
Thrown by the Modular Exponentiation operation in 'Case 2': the Base argument is blank, the Exponent argument is supplied, and the Input field is also blank — so there is no value to use as the base. The operation resolves a missing Base from the Input; if both are empty it cannot proceed and throws at ModularExponentiation.mjs:83.
Source
Thrown at src/core/operations/ModularExponentiation.mjs:83
const mod = modParam;
if (!mod) {
throw new OperationError("Modulus must be defined");
}
// Base *or* Exponent (but not both) are taken from the Input
// 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");
View on GitHub (pinned to 4290ea7539)
Solutions
- Provide a Base value either in the Base argument or in the Input field (whichever you left empty).
- If using Input as the base, ensure the upstream recipe step actually emits a value.
- Validate that at least one of Base-arg / Input is non-empty when Exponent is set.
Example fix
// before — base missing both as arg and input
modExp.run('', ['', '15', '6']); // base blank, input blank
// after — supply base via input
modExp.run('2', ['', '15', '6']); // 2^6 mod 15 Defensive patterns
Strategy: validation
Validate before calling
// Case 2: Base blank, Exponent set -> Base must come from Input.
function resolveBaseCase2(baseArg, input) {
const base = (baseArg ?? '').trim() || (input ?? '').trim();
if (!base) throw new Error('Base must be defined (fill Base arg or Input)');
return base;
} Type guard
function hasBaseForCase2(baseArg: unknown, input: unknown): boolean {
const b = (typeof baseArg === 'string' ? baseArg.trim() : '') || (typeof input === 'string' ? input.trim() : '');
return b.length > 0;
} Prevention
- When using Input as the base, ensure the upstream step emits a value.
- Provide either the Base argument or non-empty Input whenever Exponent is set.
- Validate the (baseArg | input) union is non-empty before running.
When it happens
Trigger: args: Base='', Exponent=<set>, and input='' (or whitespace). The code path at ModularExponentiation.mjs:78-84 takes base from inputVal, then rejects an empty base. Triggered whenever the user supplies only an exponent and forgets the input.
Common situations: User filled the Exponent field, left Base empty intending to use Input, but also left Input empty; a recipe where the upstream operation produced no output; whitespace-only input that trims to empty.
Related errors
- Modulus must be defined
- Exponent must be defined
- Base and Exponent must be defined
- Letter ${letter} is not included in LS47
- Unknown padding type: ${padding}
AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13).
Data as JSON: /api/errors/7d096e1874f0ddb4.
Report an issue: GitHub.