gchq/CyberChef · error · OperationError
Modulus (m) must be defined
Error message
Modulus (m) must be defined
What it means
Thrown by Modular Inverse in Case 3: the Modulus (m) argument is blank, so the operation expects to read 'm' from Input, but Input is also empty/whitespace. A modulus is required to define the ring in which the inverse is computed, so the operation aborts.
Source
Thrown at src/core/operations/ModularInverse.mjs:77
const mParam = mStr?.trim();
const inputVal = input?.trim();
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");
}View on GitHub (pinned to 4290ea7539)
Solutions
- Provide a Modulus (m) argument, or place the modulus in the Input field when Modulus is blank.
- Make sure the Input string contains an actual number, not whitespace.
- When scripting, fill exactly one of {Value, Modulus} from Input and the other as an argument.
Example fix
// before: Value set, Modulus empty, Input empty
chef.bake("Modular Inverse", ["3", ""], "");
// after: modulus from Input
chef.bake("Modular Inverse", ["3", ""], "7"); Defensive patterns
Strategy: validation
Validate before calling
const mParam = (args[1] ?? "").trim();
const inputVal = (input ?? "").trim();
if (!mParam && !inputVal) {
// supply a modulus before calling Modular Inverse
} Type guard
const hasModulusSource = (mStr, input) => Boolean((mStr ?? "").trim()) || Boolean((input ?? "").trim());
Try / catch
try { chef.bake("Modular Inverse", [a, ""], input); }
catch (e) { if (e.message.startsWith("Modulus (m) must be defined")) supplyM(); else throw e; } Prevention
- Provide Modulus explicitly or guarantee Input holds it.
- Validate that at least one modulus source is non-empty.
- Remember trim() collapses whitespace to empty.
When it happens
Trigger: run(input, args) with args[0] (Value) populated, args[1] (Modulus) empty/whitespace, and input empty/whitespace-only.
Common situations: User supplies the value as a parameter but forgets that the modulus must then come from Input; recipe where the modulus stream was renamed or disconnected; whitespace-only input.
Related errors
- Modulus must be greater than zero
- Value (a) must be defined
- Value (a) and 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/0dbabc580d8b0cd7.
Report an issue: GitHub.