{"record":{"id":"93c0fa485bf4ff40","repo":"gchq/CyberChef","slug":"switch-add-equals-can-only-be-set-to-blank-or-x","errorCode":null,"errorMessage":"Switch Add-Equals can only be set to blank, . or x","messagePattern":"Switch Add-Equals can only be set to blank, \\. or x","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/Colossus.mjs","lineNumber":404,"sourceCode":"            X2: lm[0], S1: lm[1], P5: lm[2]\n        };\n\n        const KRackOpt = args[6];\n        const setProgram = args[7];\n\n        if (KRackOpt === \"Select Program\" && setProgram !== \"\") {\n            args = this.selectProgram(setProgram, args);\n        }\n\n        const re = new RegExp(\"^$|^[.x]$\");\n        for (let qr=0;qr<3;qr++) {\n            for (let a=0;a<5;a++) {\n                if (!re.test(args[((qr*7)+(a+9))]))\n                    throw new OperationError(\"Switch R\"+(qr+1)+\"-Q\"+(a+1)+\" can only be set to blank, . or x\");\n            }\n        }\n\n        if (!re.test(args[37])) throw new OperationError(\"Switch Add-Equals can only be set to blank, . or x\");\n        if (!re.test(args[40])) throw new OperationError(\"Switch Total Motor can only be set to blank, . or x\");\n\n        // Q1,Q2,Q3,Q4,Q5,negate,counter1\n        const qbusswitches = {\n            condition: [\n                {Qswitches: [args[9], args[10], args[11], args[12], args[13]], Negate: args[14], Counter: args[15]},\n                {Qswitches: [args[16], args[17], args[18], args[19], args[20]], Negate: args[21], Counter: args[22]},\n                {Qswitches: [args[23], args[24], args[25], args[26], args[27]], Negate: args[28], Counter: args[29]}\n            ],\n            condNegateAll: args[30],\n            addition: [\n                {Qswitches: [args[32], args[33], args[34], args[35], args[36]], Equals: args[37], C1: args[38]}\n            ],\n            addNegateAll: args[39],\n            totalMotor: args[40]\n        };\n\n        const settotal = parseInt(args[42], 10);","sourceCodeStart":386,"sourceCodeEnd":422,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/Colossus.mjs#L386-L422","documentation":"Thrown when the Add-Equals switch (args[37]) fails the same ^$|^[.x]$ regex as the Q-switches. It validates the single addition-row Equals control, which must be blank, '.', or 'x'.","triggerScenarios":"Colossus.run tests args[37] (the Equals slot of the addition Q-bus condition) against the regex; any value other than '', '.', 'x' throws. This is the same constraint as [249] applied to a different switch index.","commonSituations":"Same as [249]: uppercase 'X', stray '1'/'0', null from an incomplete preset, or paste artifacts in the Equals field.","solutions":["Set args[37] (Switch Add-Equals) to '', '.', or 'x'.","Normalize uppercase/numeric encodings to lowercase x or blank.","When using 'Select Program', verify the preset populates args[37] correctly."],"exampleFix":"// before\n// args[37] = \"1\"  // throws\n// after\n// args[37] = \"x\"","handlingStrategy":"validation","validationCode":"const SWITCH_RE = /^$|^[.x]$/;\nif (!SWITCH_RE.test(args[37])) { /* fix Add-Equals before run */ }","typeGuard":"function isValidSwitch(v) { return /^$|^[.x]$/.test(v); }","tryCatchPattern":"null","preventionTips":["Only use '', '.', or lowercase 'x' for Add-Equals.","Normalize stray 'X'/'1'/'0' before running.","Check presets populate args[37]."],"tags":["colossus","switch-config","input-validation","regex"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}