gchq/CyberChef · error · OperationError
Value (a) and Modulus (m) must be defined
Error message
Value (a) and Modulus (m) must be defined
What it means
Thrown by Modular Inverse in Case 4: both the Value (a) and Modulus (m) arguments are blank. The operation has nowhere to source either operand (Input is not consulted in this branch), so it fails fast rather than proceeding with undefined values.
Source
Thrown at src/core/operations/ModularInverse.mjs:80
let a, m;
if (aParam && mParam) {
// Case 1: value and modulus both given as parameters
a = aParam;
m = mParam;
} else if (!aParam && mParam) {
// Case 2: value missing - take from input
a = inputVal;
m = mParam;
if (!a) throw new OperationError("Value (a) must be defined");
} else if (aParam && !mParam) {
// Case 3: modulus missing - take from input
a = aParam;
m = inputVal;
if (!m) throw new OperationError("Modulus (m) must be defined");
} else if (!aParam && !mParam) {
// Case 4: value and modulus both missing
throw new OperationError("Value (a) and Modulus (m) must be defined");
}
const aBI = parseBigInt(a, "Value (a)");
const mBI = parseBigInt(m, "Modulus (m)");
if (mBI <= 0n) {
throw new OperationError("Modulus must be greater than zero");
}
const aNorm = ((aBI % mBI) + mBI) % mBI;
const [g, x] = egcd(aNorm, mBI);
if (g !== 1n && g !== -1n) {
throw new OperationError("Inverse does not exist because gcd(a, m) ≠ 1");
}
let inv = x;
if (g === -1n) inv = -inv;View on GitHub (pinned to 4290ea7539)
Solutions
- Populate the Value (a) argument (and let Modulus come from Input), or populate both arguments.
- Remember Input fills at most one blank field — it cannot supply both operands.
- Restore the default recipe or fill both argument boxes explicitly.
Example fix
// before: both args empty
chef.bake("Modular Inverse", ["", ""], "3"); // still errors
// after
chef.bake("Modular Inverse", ["3", "7"], ""); Defensive patterns
Strategy: validation
Validate before calling
const aParam = (args[0] ?? "").trim();
const mParam = (args[1] ?? "").trim();
if (!aParam && !mParam) {
// both blank — fill at least Value (Input will not cover both)
} Type guard
const hasEitherArg = (aStr, mStr) => Boolean((aStr ?? "").trim()) || Boolean((mStr ?? "").trim());
Try / catch
try { chef.bake("Modular Inverse", ["", ""], input); }
catch (e) { if (e.message.includes("Value (a) and Modulus (m)")) fillArgs(); else throw e; } Prevention
- Never leave both Value and Modulus blank — Input cannot fill both.
- Restore defaults if unsure.
- Populate arguments explicitly in programmatic recipes.
When it happens
Trigger: run(input, args) with args[0] and args[1] both empty/whitespace, regardless of the Input content. Note Input is ignored entirely when both arguments are blank — supplying input here will NOT satisfy the check.
Common situations: Default recipe where both fields ship empty; user assumes Input populates both operands simultaneously; cleared both boxes to 'start fresh' and ran without refilling.
Related errors
- Modulus must be greater than zero
- Value (a) must be defined
- Modulus (m) must be defined
- Modulus must be greater than zero
- Invalid block cipher mode: ${mode}
AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13).
Data as JSON: /api/errors/050ddd04b437e5a6.
Report an issue: GitHub.