{"record":{"id":"faa6b985c0612f4f","repo":"gchq/CyberChef","slug":"2-start-must-be-between-1-and-31-faa6b9","errorCode":null,"errorMessage":"Χ2 start must be between 1 and 31","messagePattern":"Χ2 start must be between 1 and 31","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/Lorenz.mjs","lineNumber":273,"sourceCode":"            m37 = args[12],\n            m61 = args[13],\n            x1 = args[14],\n            x2 = args[15],\n            x3 = args[16],\n            x4 = args[17],\n            x5 = args[18];\n\n        this.reverseTable();\n\n        if (s1<1 || s1>43) throw new OperationError(\"Ψ1 start must be between 1 and 43\");\n        if (s2<1 || s2>47) throw new OperationError(\"Ψ2 start must be between 1 and 47\");\n        if (s3<1 || s3>51) throw new OperationError(\"Ψ3 start must be between 1 and 51\");\n        if (s4<1 || s4>53) throw new OperationError(\"Ψ4 start must be between 1 and 53\");\n        if (s5<1 || s5>59) throw new OperationError(\"Ψ5 start must be between 1 and 59\");\n        if (m37<1 || m37>37) throw new OperationError(\"Μ37 start must be between 1 and 37\");\n        if (m61<1 || m61>61) throw new OperationError(\"Μ61 start must be between 1 and 61\");\n        if (x1<1 || x1>41) throw new OperationError(\"Χ1 start must be between 1 and 41\");\n        if (x2<1 || x2>31) throw new OperationError(\"Χ2 start must be between 1 and 31\");\n        if (x3<1 || x3>29) throw new OperationError(\"Χ3 start must be between 1 and 29\");\n        if (x4<1 || x4>26) throw new OperationError(\"Χ4 start must be between 1 and 26\");\n        if (x5<1 || x5>23) throw new OperationError(\"Χ5 start must be between 1 and 23\");\n\n        // Initialise chosen wheel pattern\n        let chosenSetting = \"\";\n        if (pattern === \"Custom\") {\n            const re = new RegExp(\"^[.xX]*$\");\n            if (lugs1.length !== 43 || !re.test(lugs1)) throw new OperationError(\"Ψ1 custom lugs must be 43 long and can only include . or x \");\n            if (lugs2.length !== 47 || !re.test(lugs2)) throw new OperationError(\"Ψ2 custom lugs must be 47 long and can only include . or x\");\n            if (lugs3.length !== 51 || !re.test(lugs3)) throw new OperationError(\"Ψ3 custom lugs must be 51 long and can only include . or x\");\n            if (lugs4.length !== 53 || !re.test(lugs4)) throw new OperationError(\"Ψ4 custom lugs must be 53 long and can only include . or x\");\n            if (lugs5.length !== 59 || !re.test(lugs5)) throw new OperationError(\"Ψ5 custom lugs must be 59 long and can only include . or x\");\n            if (lugm37.length !== 37 || !re.test(lugm37)) throw new OperationError(\"M37 custom lugs must be 37 long and can only include . or x\");\n            if (lugm61.length !== 61 || !re.test(lugm61)) throw new OperationError(\"M61 custom lugs must be 61 long and can only include . or x\");\n            if (lugx1.length !== 41 || !re.test(lugx1)) throw new OperationError(\"Χ1 custom lugs must be 41 long and can only include . or x\");\n            if (lugx2.length !== 31 || !re.test(lugx2)) throw new OperationError(\"Χ2 custom lugs must be 31 long and can only include . or x\");\n            if (lugx3.length !== 29 || !re.test(lugx3)) throw new OperationError(\"Χ3 custom lugs must be 29 long and can only include . or x\");","sourceCodeStart":255,"sourceCodeEnd":291,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/Lorenz.mjs#L255-L291","documentation":"Thrown by the Lorenz operation when the Χ2 (chi-2) wheel start position is out of range. The Χ2 wheel has 31 cams, so the 1-indexed start must be in [1, 31]. Guard is on line 273 of src/core/operations/Lorenz.mjs.","triggerScenarios":"Calling Lorenz.run() with args[15] ('Χ2 start (1-31)') less than 1 or greater than 31.","commonSituations":"Chi wheel set to 0; value sized for Χ1 (41) reused on Χ2; stale recipe value.","solutions":["Set the Χ2 start argument to an integer in [1, 31].","Clamp generated values with `((n - 1) % 31) + 1`.","Reset wheel-start fields to 1 and re-enter."],"exampleFix":"// before: args[15] = 0  -> throws\n// after:  args[15] = 1  -> ok","handlingStrategy":"validation","validationCode":"// Χ2 start (args[15]) must be in [1, 31]\nfunction clampWheelStart(n, size) {\n  if (!Number.isFinite(n)) throw new Error(`start must be a number, got ${n}`);\n  return ((Math.floor(n) - 1) % size + size) % size + 1;\n}\nargs[15] = clampWheelStart(args[15], 31);","typeGuard":"const isChi2Start = (v) => Number.isInteger(v) && v >= 1 && v <= 31;","tryCatchPattern":"try {\n  lorenz.run(input, args);\n} catch (err) {\n  if (err instanceof OperationError && /Χ2 start/.test(err.message)) {\n    args[15] = 1;\n  } else throw err;\n}","preventionTips":["Χ2 has 31 cams; smaller than Χ1 — do not reuse Χ1's value blindly.","Default to 1, never 0.","Fold generated values into [1, 31] before running."],"tags":["lorenz","wheel-position","argument-validation","rotor-cipher","numeric-range"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}