{"record":{"id":"9b3edbdf1c3ef036","repo":"gchq/CyberChef","slug":"switch-r-qr-1-q-a-1-can-only-be-set-to-blank","errorCode":null,"errorMessage":"Switch R${qr+1}-Q${a+1} can only be set to blank, . or x","messagePattern":"Switch R(.+?)-Q(.+?) can only be set to blank, \\. or x","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/Colossus.mjs","lineNumber":400,"sourceCode":"        if (limitation.includes(\"Χ2\")) lm[0] = true;\n        if (limitation.includes(\"Ψ1\")) lm[1] = true;\n        if (limitation.includes(\"P5\")) lm[2] = true;\n        const limit = {\n            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],","sourceCodeStart":382,"sourceCodeEnd":418,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/Colossus.mjs#L382-L418","documentation":"Thrown during Colossus Q-switch validation: each of the 15 conditional R1–R3 / Q1–Q5 switches must be blank, '.', or 'x'. The regex ^$|^[.x]$ is tested against args[9]..args[29] (stepping 7 per row, 5 per row); any other value names the offending switch (R{qr+1}-Q{a+1}).","triggerScenarios":"Colossus.run iterates qr=0..2 and a=0..4 testing args[(qr*7)+(a+9)]. A value other than '', '.', or 'x' (e.g. 'X' uppercase, '1', 'Y', null) throws 'Switch R{n}-Q{m} can only be set to blank, . or x'.","commonSituations":"User exports/imports a program with uppercase 'X', fills cells with '1'/'0', or a 'Select Program' preset leaves malformed values. Copy-paste from a table can introduce full-width chars or spaces.","solutions":["Set each R/Q switch to exactly '', '.', or 'x' (lowercase x).","If using 'Select Program', ensure selectProgram returns clean values; otherwise clear and set switches manually.","Normalize values: uppercase 'X' → 'x', '1'/'0' → 'x'/'.'.","Validate the 15 cells before running."],"exampleFix":"// before\n// args[9] = \"X\"  // uppercase → throws\n// after\n// args[9] = \"x\"","handlingStrategy":"validation","validationCode":"const SWITCH_RE = /^$|^[.x]$/;\nfor (let qr=0; qr<3; qr++) {\n  for (let a=0; a<5; a++) {\n    if (!SWITCH_RE.test(args[(qr*7)+(a+9)])) { /* fix args before run */ }\n  }\n}","typeGuard":"function isValidSwitch(v) { return /^$|^[.x]$/.test(v); }","tryCatchPattern":"null","preventionTips":["Only use '', '.', or lowercase 'x' in Q-switch cells.","Normalize uppercase 'X' and '1'/'0' to 'x'/'.' before running.","Verify 'Select Program' presets populate all 15 cells cleanly."],"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"}