{"record":{"id":"118fabb2ee5a8b8b","repo":"gchq/CyberChef","slug":"base-and-exponent-must-be-defined","errorCode":null,"errorMessage":"Base and Exponent must be defined","messagePattern":"Base and Exponent must be defined","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/ModularExponentiation.mjs","lineNumber":94,"sourceCode":"            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\n        // Check for invalid modulus (parseBigInt eliminates negatives)\n        if (modBI === 0n) {\n            throw new OperationError(\"Modulus must be greater than zero\");\n        }\n\n        return modPow(baseBI, expBI, modBI).toString();\n    }\n}\n\nexport default ModularExponentiation;\n","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/ModularExponentiation.mjs#L76-L112","documentation":"Thrown by the Modular Exponentiation operation in 'Case 4': both the Base and Exponent arguments are blank AND the Input field is blank (or whitespace). With nothing supplied for base, exponent, or input, the operation has no values to compute with and throws at ModularExponentiation.mjs:94. (Note: if Input is non-empty while both args are blank, a different error — 'Ambiguous input' — is thrown at line 95.)","triggerScenarios":"args: Base='', Exponent='', and input=''. All three sources empty. Raised at ModularExponentiation.mjs:92-94. Distinguish from the ambiguous case (line 95) where Input is present but both args are blank.","commonSituations":"User cleared all fields; a recipe with no upstream output and no inline base/exponent; testing the operation with empty input.","solutions":["Supply at least a Modulus (required), plus Base and Exponent via the arguments and/or the Input field.","Remember the input rule: exactly one of Base/Exponent may be taken from Input; provide the other as an argument.","If building recipes programmatically, default base and exponent to '0'/'1' or wire Input to a non-empty upstream step."],"exampleFix":"// before — everything empty\nmodExp.run('', ['', '15', '']);   // base, exp, input all blank\n\n// after — provide base & exponent inline\nmodExp.run('', ['2', '15', '6']);  // 2^6 mod 15","handlingStrategy":"validation","validationCode":"// Case 4: both Base and Exponent args blank -> need non-empty Input AND disambiguation.\nfunction resolveBaseExpCase4(baseArg, expArg, input) {\n  const inp = (input ?? '').trim();\n  const b = (baseArg ?? '').trim();\n  const e = (expArg ?? '').trim();\n  if (!b && !e && !inp) throw new Error('Base and Exponent must be defined');\n  if (!b && !e && inp) throw new Error('Ambiguous: specify Base or Exponent when using Input');\n  return { base: b || inp, exp: e || inp };\n}","typeGuard":"function hasBaseAndExp(v: { base?: unknown; exp?: unknown; input?: unknown }): boolean {\n  const b = typeof v.base === 'string' ? v.base.trim() : '';\n  const e = typeof v.exp === 'string' ? v.exp.trim() : '';\n  const i = typeof v.input === 'string' ? v.input.trim() : '';\n  return (b.length + e.length + i.length) > 0;\n}","tryCatchPattern":null,"preventionTips":["Always supply a Modulus, plus Base and Exponent via args and/or Input.","Remember exactly one of Base/Exponent can come from Input — provide the other as an arg.","Default base/exponent to safe values ('0'/'1') when building recipes programmatically."],"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"}