gchq/CyberChef · error · OperationError
Value a must be defined
Error message
Value a must be defined
What it means
Thrown by the Extended GCD operation when computing the Extended Euclidean Algorithm. The operation accepts values a and b either as arguments or falls back to the input field. This specific error fires when 'Value a' is left blank as a parameter AND the input field is also empty or whitespace, while 'Value b' was provided. The operation cannot compute gcd(a,b) without a value for a.
Source
Thrown at src/core/operations/ExtendedGCD.mjs:73
run(input, args) {
const [aStr, bStr] = args;
// Trim everything so "" and " " count as empty
const aParam = aStr?.trim();
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.View on GitHub (pinned to 4290ea7539)
Solutions
- Enter a numeric value in the 'Value a' argument field.
- Alternatively, enter a numeric value in the Input field (it will be used as Value a when the argument is blank).
- Ensure the value is a valid integer string (decimal or hex) accepted by parseBigInt.
Example fix
// before: args = ['', '48'], input = '' // Value a blank, input blank -> error // after: args = ['36', '48'], input = '' // Both values supplied as arguments // or: args = ['', '48'], input = '36' // a taken from input
Defensive patterns
Strategy: validation
Validate before calling
// Before calling ExtendedGCD, ensure Value a is available
const aParam = (args[0] || '').trim();
const inputVal = (input || '').trim();
if (!aParam && !inputVal) {
// prompt user or supply default
throw new Error('Value a must be provided via argument or input');
} Prevention
- Always populate at least one source for each operand (argument or input).
- Trim and check inputs before passing to the operation.
- Validate that values are non-empty numeric strings before running.
When it happens
Trigger: run(input, args) where args[0] ('Value a') is empty/whitespace, args[1] ('Value b') is non-empty, and the input string (inputVal = input?.trim()) is also empty/whitespace. Specifically the !aParam && bParam branch at line 69 where inputVal is falsy.
Common situations: User provides only Value b in the arguments panel and forgets to type a number into either Value a or the Input field. Also occurs when the input field contains only whitespace characters that get trimmed to empty.
Related errors
- Value b must be defined
- Values a and b must be defined
- Modulus must be defined
- Base must be defined
- Exponent must be defined
AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13).
Data as JSON: /api/errors/bd193ff3ca67484c.
Report an issue: GitHub.