{"record":{"id":"7d096e1874f0ddb4","repo":"gchq/CyberChef","slug":"base-must-be-defined","errorCode":null,"errorMessage":"Base must be defined","messagePattern":"Base must be defined","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/ModularExponentiation.mjs","lineNumber":83,"sourceCode":"\n        const mod = modParam;\n        if (!mod) {\n            throw new OperationError(\"Modulus must be defined\");\n        }\n\n        // Base *or* Exponent (but not both) are taken from the Input\n        // if their boxes are empty.\n        let base, exp;\n        if (baseParam && expParam) {\n            // Case 1: base and exponent both given as parameters\n            base = baseParam;\n            exp  = expParam;\n        } else if (!baseParam && expParam) {\n            // Case 2: base missing - take from input\n            base = inputVal;\n            exp  = expParam;\n            if (!base) {\n                throw new OperationError(\"Base must be defined\");\n            }\n        } else if (baseParam && !expParam) {\n            // Case 3: exponent missing - take from input\n            base = baseParam;\n            exp  = inputVal;\n            if (!exp) {\n                throw new OperationError(\"Exponent must be defined\");\n            }\n        } else if (!inputVal) {\n            // Case 4: base and exponent both missing\n            throw new OperationError(\"Base and Exponent must be defined\");\n        } else throw new OperationError(\"Ambiguous input: specify either Base or Exponent when using Input\");\n\n        // Parse numbers\n        const baseBI = parseBigInt(base, \"Base\");\n        const expBI  = parseBigInt(exp, \"Exponent\");\n        const modBI  = parseBigInt(mod, \"Modulus\");\n","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/ModularExponentiation.mjs#L65-L101","documentation":"Thrown by the Modular Exponentiation operation in 'Case 2': the Base argument is blank, the Exponent argument is supplied, and the Input field is also blank — so there is no value to use as the base. The operation resolves a missing Base from the Input; if both are empty it cannot proceed and throws at ModularExponentiation.mjs:83.","triggerScenarios":"args: Base='', Exponent=<set>, and input='' (or whitespace). The code path at ModularExponentiation.mjs:78-84 takes base from inputVal, then rejects an empty base. Triggered whenever the user supplies only an exponent and forgets the input.","commonSituations":"User filled the Exponent field, left Base empty intending to use Input, but also left Input empty; a recipe where the upstream operation produced no output; whitespace-only input that trims to empty.","solutions":["Provide a Base value either in the Base argument or in the Input field (whichever you left empty).","If using Input as the base, ensure the upstream recipe step actually emits a value.","Validate that at least one of Base-arg / Input is non-empty when Exponent is set."],"exampleFix":"// before — base missing both as arg and input\nmodExp.run('', ['', '15', '6']);   // base blank, input blank\n\n// after — supply base via input\nmodExp.run('2', ['', '15', '6']);  // 2^6 mod 15","handlingStrategy":"validation","validationCode":"// Case 2: Base blank, Exponent set -> Base must come from Input.\nfunction resolveBaseCase2(baseArg, input) {\n  const base = (baseArg ?? '').trim() || (input ?? '').trim();\n  if (!base) throw new Error('Base must be defined (fill Base arg or Input)');\n  return base;\n}","typeGuard":"function hasBaseForCase2(baseArg: unknown, input: unknown): boolean {\n  const b = (typeof baseArg === 'string' ? baseArg.trim() : '') || (typeof input === 'string' ? input.trim() : '');\n  return b.length > 0;\n}","tryCatchPattern":null,"preventionTips":["When using Input as the base, ensure the upstream step emits a value.","Provide either the Base argument or non-empty Input whenever Exponent is set.","Validate the (baseArg | input) union is non-empty before running."],"tags":["modular-exponentiation","crypto","rsa","validation","argument-required"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}