gchq/CyberChef · error · OperationError

Value (a) must be defined

Error message

Value (a) must be defined

What it means

Thrown by Modular Inverse in Case 2: the Value (a) argument is blank, so the operation expects to read 'a' from the Input field, but Input is also empty/whitespace. Without a value there is nothing to invert, so the operation aborts before parsing.

Source

Thrown at src/core/operations/ModularInverse.mjs:72

    run(input, args) {
        const [aStr, mStr] = args;

        // Trim everything so "" and "   " count as empty
        const aParam = aStr?.trim();
        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;

View on GitHub (pinned to 4290ea7539)

Solutions

  1. Supply a non-empty Value (a) argument, or put the value in the Input field when Value is blank.
  2. Ensure the input string is not just whitespace — trim() treats it as missing.
  3. If scripting, pass the value through Input and leave Value empty, or vice versa, but never both empty.

Example fix

// before: Value empty, Input empty
chef.bake("Modular Inverse", ["", "7"], "");
// after: supply 'a' in Input
chef.bake("Modular Inverse", ["", "7"], "3");
Defensive patterns

Strategy: validation

Validate before calling

const aParam = (args[0] ?? "").trim();
const inputVal = (input ?? "").trim();
if (!aParam && !inputVal) {
  // do not call Modular Inverse; supply a value first
}

Type guard

const hasValueSource = (aStr, input) =>
  Boolean((aStr ?? "").trim()) || Boolean((input ?? "").trim());

Try / catch

try { chef.bake("Modular Inverse", ["", m], input); }
catch (e) { if (e.message.startsWith("Value (a) must be defined")) supplyA(); else throw e; }

Prevention

When it happens

Trigger: run(input, args) with args[0] (Value) empty/whitespace, args[1] (Modulus) populated, and input empty or whitespace-only. The trim() at line 58 makes ' ' count as empty.

Common situations: User clears the Value box intending to feed it via Input but forgets to paste anything into Input; recipe wired so the value is supplied on a different stream than expected; trailing whitespace only.

Related errors


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