{"record":{"id":"dea20db4d7e9ddb7","repo":"gchq/CyberChef","slug":"exponent-must-be-defined","errorCode":null,"errorMessage":"Exponent must be defined","messagePattern":"Exponent must be defined","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/ModularExponentiation.mjs","lineNumber":90,"sourceCode":"        // 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\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    }","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/ModularExponentiation.mjs#L72-L108","documentation":"Thrown by the Modular Exponentiation operation in 'Case 3': the Base argument is supplied, the Exponent argument is blank, and the Input field is also blank — so there is no value to use as the exponent. The operation resolves a missing Exponent from the Input; if both are empty it throws at ModularExponentiation.mjs:90.","triggerScenarios":"args: Base=<set>, Exponent='', and input='' (or whitespace). The code path at ModularExponentiation.mjs:85-91 takes exp from inputVal, then rejects an empty exponent. Triggered when the user supplies only a base and forgets the input.","commonSituations":"User filled the Base field, left Exponent empty intending to use Input, but also left Input empty; upstream recipe step emitted nothing; whitespace-only input.","solutions":["Provide an Exponent value either in the Exponent argument or in the Input field.","If using Input as the exponent, ensure the upstream step emits a value.","Validate that at least one of Exponent-arg / Input is non-empty when Base is set."],"exampleFix":"// before — exponent missing both as arg and input\nmodExp.run('', ['2', '15', '']);   // exp blank, input blank\n\n// after — supply exponent via input\nmodExp.run('6', ['2', '15', '']);  // 2^6 mod 15","handlingStrategy":"validation","validationCode":"// Case 3: Exponent blank, Base set -> Exponent must come from Input.\nfunction resolveExpCase3(expArg, input) {\n  const exp = (expArg ?? '').trim() || (input ?? '').trim();\n  if (!exp) throw new Error('Exponent must be defined (fill Exponent arg or Input)');\n  return exp;\n}","typeGuard":"function hasExpForCase3(expArg: unknown, input: unknown): boolean {\n  const e = (typeof expArg === 'string' ? expArg.trim() : '') || (typeof input === 'string' ? input.trim() : '');\n  return e.length > 0;\n}","tryCatchPattern":null,"preventionTips":["When using Input as the exponent, ensure the upstream step emits a value.","Provide either the Exponent argument or non-empty Input whenever Base is set.","Validate the (expArg | 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"}