{"record":{"id":"dab50b2639f89b96","repo":"gchq/CyberChef","slug":"values-a-and-b-must-be-defined","errorCode":null,"errorMessage":"Values a and b must be defined","messagePattern":"Values a and b must be defined","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/ExtendedGCD.mjs","lineNumber":81,"sourceCode":"        let a, b;\n\n        if (aParam && bParam) {\n            // Case 1: both values given as parameters\n            a = aParam;\n            b = bParam;\n        } else if (!aParam && bParam) {\n            // Case 2: a missing - take from input\n            a = inputVal;\n            b = bParam;\n            if (!a) throw new OperationError(\"Value a must be defined\");\n        } else if (aParam && !bParam) {\n            // Case 3: b missing - take from input\n            a = aParam;\n            b = inputVal;\n            if (!b) throw new OperationError(\"Value b must be defined\");\n        } else if (!aParam && !bParam) {\n            // Case 4: both values missing\n            throw new OperationError(\"Values a and b must be defined\");\n        }\n\n        const aBI = parseBigInt(a, \"Value a\");\n        const bBI = parseBigInt(b, \"Value b\");\n\n        const [g, x, y] = egcd(aBI, bBI);\n        const gcd = g < 0n ? -g : g;\n\n        // Format output string bearing in mind that crypto-grade numbers\n        // may greatly exceed the line length.\n        let output = \"gcd: \" + gcd.toString() + \"\\n\\n\";\n        output += \"Bezout coefficients:\\n\";\n        output += \"x = \" + x.toString() + \"\\n\";\n        output += \"y = \" + y.toString() + \"\\n\\n\";\n\n        return output;\n    }\n}","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/ExtendedGCD.mjs#L63-L99","documentation":"Thrown by the Extended GCD operation when computing the Extended Euclidean Algorithm. This fires when BOTH 'Value a' and 'Value b' are left blank as parameters AND the input field is also empty or whitespace. With no operands available at all, the algorithm cannot run.","triggerScenarios":"run(input, args) where args[0] and args[1] are both empty/whitespace and input is also empty/whitespace. This is the !aParam && !bParam branch at line 79.","commonSituations":"User runs the Extended GCD operation without filling in any values, expecting defaults. Common when the operation is added to a recipe but not yet configured.","solutions":["Provide Value a and Value b in the argument fields.","Provide at least one value via the argument fields and the other via the Input field.","Provide both values in the Input field is not sufficient alone — at least one argument or restructure usage is needed."],"exampleFix":"// before: args = ['', ''], input = '' -> error\n\n// after: args = ['36', '48'], input = ''","handlingStrategy":"validation","validationCode":"// Ensure at least one value source exists before running\nconst aParam = (args[0] || '').trim();\nconst bParam = (args[1] || '').trim();\nconst inputVal = (input || '').trim();\nif (!aParam && !bParam && !inputVal) {\n  throw new Error('At least one value for a or b must be provided');\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always fill in Value a and Value b argument fields.","Remember that input is only used as a fallback for a single missing value.","Validate recipe configuration before execution."],"tags":["validation","number-theory","argument-required"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}