gchq/CyberChef · error · OperationError

Value b must be defined

Error message

Value b must be defined

What it means

Thrown by the Extended GCD operation when computing the Extended Euclidean Algorithm. This fires when 'Value b' is left blank as a parameter AND the input field is also empty or whitespace, while 'Value a' was provided. The operation needs both integers to compute gcd(a,b) and Bezout coefficients.

Source

Thrown at src/core/operations/ExtendedGCD.mjs:78

        const bParam = bStr?.trim();
        const inputVal = input?.trim();

        let a, b;

        if (aParam && bParam) {
            // Case 1: both values given as parameters
            a = aParam;
            b = bParam;
        } else if (!aParam && bParam) {
            // Case 2: a missing - take from input
            a = inputVal;
            b = bParam;
            if (!a) throw new OperationError("Value a must be defined");
        } else if (aParam && !bParam) {
            // Case 3: b missing - take from input
            a = aParam;
            b = inputVal;
            if (!b) throw new OperationError("Value b must be defined");
        } else if (!aParam && !bParam) {
            // Case 4: both values missing
            throw new OperationError("Values a and b must be defined");
        }

        const aBI = parseBigInt(a, "Value a");
        const bBI = parseBigInt(b, "Value b");

        const [g, x, y] = egcd(aBI, bBI);
        const gcd = g < 0n ? -g : g;

        // Format output string bearing in mind that crypto-grade numbers
        // may greatly exceed the line length.
        let output = "gcd: " + gcd.toString() + "\n\n";
        output += "Bezout coefficients:\n";
        output += "x = " + x.toString() + "\n";
        output += "y = " + y.toString() + "\n\n";

View on GitHub (pinned to 4290ea7539)

Solutions

  1. Enter a numeric value in the 'Value b' argument field.
  2. Alternatively, enter a numeric value in the Input field (it will be used as Value b when the argument is blank).
  3. Ensure the value is a valid integer string accepted by parseBigInt.

Example fix

// before: args = ['36', ''], input = ''
// Value b blank, input blank -> error

// after: args = ['36', '48'], input = ''
// or: args = ['36', ''], input = '48'
Defensive patterns

Strategy: validation

Validate before calling

// Before calling ExtendedGCD, ensure Value b is available
const bParam = (args[1] || '').trim();
const inputVal = (input || '').trim();
if (!bParam && !inputVal) {
  throw new Error('Value b must be provided via argument or input');
}

Prevention

When it happens

Trigger: run(input, args) where args[0] ('Value a') is non-empty, args[1] ('Value b') is empty/whitespace, and the input string is also empty/whitespace. Specifically the aParam && !bParam branch at line 74 where inputVal is falsy.

Common situations: User provides only Value a in the arguments panel and leaves both Value b and the Input field empty. Also when the input field contains only whitespace.

Related errors


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