gchq/CyberChef · error · OperationError
Base and Exponent must be defined
Error message
Base and Exponent must be defined
What it means
Thrown by the Modular Exponentiation operation in 'Case 4': both the Base and Exponent arguments are blank AND the Input field is blank (or whitespace). With nothing supplied for base, exponent, or input, the operation has no values to compute with and throws at ModularExponentiation.mjs:94. (Note: if Input is non-empty while both args are blank, a different error — 'Ambiguous input' — is thrown at line 95.)
Source
Thrown at src/core/operations/ModularExponentiation.mjs:94
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();
}
}
export default ModularExponentiation;
View on GitHub (pinned to 4290ea7539)
Solutions
- Supply at least a Modulus (required), plus Base and Exponent via the arguments and/or the Input field.
- Remember the input rule: exactly one of Base/Exponent may be taken from Input; provide the other as an argument.
- If building recipes programmatically, default base and exponent to '0'/'1' or wire Input to a non-empty upstream step.
Example fix
// before — everything empty
modExp.run('', ['', '15', '']); // base, exp, input all blank
// after — provide base & exponent inline
modExp.run('', ['2', '15', '6']); // 2^6 mod 15 Defensive patterns
Strategy: validation
Validate before calling
// Case 4: both Base and Exponent args blank -> need non-empty Input AND disambiguation.
function resolveBaseExpCase4(baseArg, expArg, input) {
const inp = (input ?? '').trim();
const b = (baseArg ?? '').trim();
const e = (expArg ?? '').trim();
if (!b && !e && !inp) throw new Error('Base and Exponent must be defined');
if (!b && !e && inp) throw new Error('Ambiguous: specify Base or Exponent when using Input');
return { base: b || inp, exp: e || inp };
} Type guard
function hasBaseAndExp(v: { base?: unknown; exp?: unknown; input?: unknown }): boolean {
const b = typeof v.base === 'string' ? v.base.trim() : '';
const e = typeof v.exp === 'string' ? v.exp.trim() : '';
const i = typeof v.input === 'string' ? v.input.trim() : '';
return (b.length + e.length + i.length) > 0;
} Prevention
- Always supply a Modulus, plus Base and Exponent via args and/or Input.
- Remember exactly one of Base/Exponent can come from Input — provide the other as an arg.
- Default base/exponent to safe values ('0'/'1') when building recipes programmatically.
When it happens
Trigger: args: Base='', Exponent='', and input=''. All three sources empty. Raised at ModularExponentiation.mjs:92-94. Distinguish from the ambiguous case (line 95) where Input is present but both args are blank.
Common situations: User cleared all fields; a recipe with no upstream output and no inline base/exponent; testing the operation with empty input.
Related errors
- Modulus must be defined
- Base must be defined
- 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/118fabb2ee5a8b8b.
Report an issue: GitHub.