{"record":{"id":"1aa914c8988cb97e","repo":"gchq/CyberChef","slug":"value-b-must-be-defined","errorCode":null,"errorMessage":"Value b must be defined","messagePattern":"Value b must be defined","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/ExtendedGCD.mjs","lineNumber":78,"sourceCode":"        const bParam = bStr?.trim();\n        const inputVal = input?.trim();\n\n        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","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/ExtendedGCD.mjs#L60-L96","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Enter a numeric value in the 'Value b' argument field.","Alternatively, enter a numeric value in the Input field (it will be used as Value b when the argument is blank).","Ensure the value is a valid integer string accepted by parseBigInt."],"exampleFix":"// before: args = ['36', ''], input = ''\n// Value b blank, input blank -> error\n\n// after: args = ['36', '48'], input = ''\n// or: args = ['36', ''], input = '48'","handlingStrategy":"validation","validationCode":"// Before calling ExtendedGCD, ensure Value b is available\nconst bParam = (args[1] || '').trim();\nconst inputVal = (input || '').trim();\nif (!bParam && !inputVal) {\n  throw new Error('Value b must be provided via argument or input');\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always provide Value b via the argument or input field.","Validate both operands are present before running.","Use the input field as a fallback when one argument is intentionally left blank."],"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"}