gchq/CyberChef · error · OperationError

Χ2 custom lugs must be 31 long and can only include . or x

Error message

Χ2 custom lugs must be 31 long and can only include . or x

What it means

Thrown by the Lorenz SZ operation when 'Wheel Pattern' is 'Custom' and the Χ2 (chi-2) lug string (arg[27], 'Χ2 lugs (31)') is invalid. The physical Χ2 wheel has 31 cam positions, so the supplied string must be exactly 31 characters drawn from {'.', 'x', 'X'}. Length and the regex /^[.xX]*$/ are both enforced at Lorenz.mjs:290.

Source

Thrown at src/core/operations/Lorenz.mjs:290

        if (x1<1 || x1>41) throw new OperationError("Χ1 start must be between 1 and 41");
        if (x2<1 || x2>31) throw new OperationError("Χ2 start must be between 1 and 31");
        if (x3<1 || x3>29) throw new OperationError("Χ3 start must be between 1 and 29");
        if (x4<1 || x4>26) throw new OperationError("Χ4 start must be between 1 and 26");
        if (x5<1 || x5>23) throw new OperationError("Χ5 start must be between 1 and 23");

        // Initialise chosen wheel pattern
        let chosenSetting = "";
        if (pattern === "Custom") {
            const re = new RegExp("^[.xX]*$");
            if (lugs1.length !== 43 || !re.test(lugs1)) throw new OperationError("Ψ1 custom lugs must be 43 long and can only include . or x ");
            if (lugs2.length !== 47 || !re.test(lugs2)) throw new OperationError("Ψ2 custom lugs must be 47 long and can only include . or x");
            if (lugs3.length !== 51 || !re.test(lugs3)) throw new OperationError("Ψ3 custom lugs must be 51 long and can only include . or x");
            if (lugs4.length !== 53 || !re.test(lugs4)) throw new OperationError("Ψ4 custom lugs must be 53 long and can only include . or x");
            if (lugs5.length !== 59 || !re.test(lugs5)) throw new OperationError("Ψ5 custom lugs must be 59 long and can only include . or x");
            if (lugm37.length !== 37 || !re.test(lugm37)) throw new OperationError("M37 custom lugs must be 37 long and can only include . or x");
            if (lugm61.length !== 61 || !re.test(lugm61)) throw new OperationError("M61 custom lugs must be 61 long and can only include . or x");
            if (lugx1.length !== 41 || !re.test(lugx1)) throw new OperationError("Χ1 custom lugs must be 41 long and can only include . or x");
            if (lugx2.length !== 31 || !re.test(lugx2)) throw new OperationError("Χ2 custom lugs must be 31 long and can only include . or x");
            if (lugx3.length !== 29 || !re.test(lugx3)) throw new OperationError("Χ3 custom lugs must be 29 long and can only include . or x");
            if (lugx4.length !== 26 || !re.test(lugx4)) throw new OperationError("Χ4 custom lugs must be 26 long and can only include . or x");
            if (lugx5.length !== 23 || !re.test(lugx5)) throw new OperationError("Χ5 custom lugs must be 23 long and can only include . or x");
            chosenSetting = INIT_PATTERNS["No Pattern"];
            chosenSetting.S[1] = this.readLugs(lugs1);
            chosenSetting.S[2] = this.readLugs(lugs2);
            chosenSetting.S[3] = this.readLugs(lugs3);
            chosenSetting.S[4] = this.readLugs(lugs4);
            chosenSetting.S[5] = this.readLugs(lugs5);
            chosenSetting.M[1] = this.readLugs(lugm61);
            chosenSetting.M[2] = this.readLugs(lugm37);
            chosenSetting.X[1] = this.readLugs(lugx1);
            chosenSetting.X[2] = this.readLugs(lugx2);
            chosenSetting.X[3] = this.readLugs(lugx3);
            chosenSetting.X[4] = this.readLugs(lugx4);
            chosenSetting.X[5] = this.readLugs(lugx5);
        } else {
            chosenSetting = INIT_PATTERNS[pattern];

View on GitHub (pinned to 4290ea7539)

Solutions

  1. Set the Χ2 lug string to exactly 31 characters using only '.', 'x', or 'X' (31 is the chi-2 wheel cam count).
  2. Switch off 'Custom' and use a preset wheel pattern (KH/ZMUG/BREAM/No Pattern) to bypass custom-lug validation entirely.
  3. Validate length and alphabet before calling the operation (see validationCode).
  4. Confirm you are filling the Χ2 field, not a Ψ or Μ field of a different length.

Example fix

// before
lugx2 = "x..xxx...x.xxxx..xx..x..xx.xx..x";  // 32 chars

// after — exactly 31 chars
lugx2 = "x..xxx...x.xxxx..xx..x..xx.xx..";
Defensive patterns

Strategy: validation

Validate before calling

const CHI2_LEN = 31;
const lugRe = /^[.xX]*$/;
function validChi2(lugx2) {
  return typeof lugx2 === 'string' && lugx2.length === CHI2_LEN && lugRe.test(lugx2);
}
if (!validChi2(args[27])) throw new Error('Χ2 lugs must be 31 chars of . x X');

Type guard

function isChi2Lugs(v): v is string {
  return typeof v === 'string' && v.length === 31 && /^[.xX]*$/.test(v);
}

Prevention

When it happens

Trigger: pattern='Custom' with a lugx2 value whose length != 31 or containing any character other than '.', 'x', 'X'. Because the Χ1 check (line 289) runs first, you only reach this line once lugx1 is already valid.

Common situations: Reusing a 41-char Χ1 pattern for Χ2; source documents that encode the chi-2 wheel with a different length; copy/paste that drops or adds a character; using 'O' instead of 'x' for an active lug.

Related errors


AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13). Data as JSON: /api/errors/6f3fe335405acd54. Report an issue: GitHub.