gchq/CyberChef · error · OperationError

Offset cannot be negative

Error message

Offset cannot be negative

What it means

The Bombe searches for the crib starting at a given offset into the ciphertext. A negative offset would slice the string from the wrong position, so the operation rejects it before processing.

Source

Thrown at src/core/operations/Bombe.mjs:138

        for (let i=0; i<4; i++) {
            if (i === 0 && model === "3-rotor") {
                // No fourth rotor
                continue;
            }
            let rstr = args[i + 1];
            // The Bombe doesn't take stepping into account so we'll just ignore it here
            if (rstr.includes("<")) {
                rstr = rstr.split("<", 2)[0];
            }
            rotors.push(rstr);
        }
        // Rotors are handled in reverse
        rotors.reverse();
        if (crib.length === 0) {
            throw new OperationError("Crib cannot be empty");
        }
        if (offset < 0) {
            throw new OperationError("Offset cannot be negative");
        }
        // For symmetry with the Enigma op, for the input we'll just remove all invalid characters
        input = input.replace(/[^A-Za-z]/g, "").toUpperCase();
        crib = crib.replace(/[^A-Za-z]/g, "").toUpperCase();
        const ciphertext = input.slice(offset);
        const reflector = new Reflector(reflectorstr);
        let update;
        if (isWorkerEnvironment()) {
            update = this.updateStatus;
        } else {
            update = undefined;
        }
        const bombe = new BombeMachine(rotors, reflector, ciphertext, crib, check, update);
        const result = bombe.run();
        return {
            nLoops: bombe.nLoops,
            result: result
        };

View on GitHub (pinned to 4290ea7539)

Solutions

  1. Set offset to 0 or a positive integer not exceeding the ciphertext length.
  2. Clamp offset in the UI to >= 0.
  3. Verify the offset plus crib length does not exceed the input length.

Example fix

// before
offset = -1
// after
offset = 0
Defensive patterns

Strategy: validation

Validate before calling

if (!Number.isInteger(offset) || offset < 0) throw new Error('Offset must be a non-negative integer');

Type guard

function isValidOffset(n) { return Number.isInteger(n) && n >= 0; }

Prevention

When it happens

Trigger: Calling Bombe.run with a negative offset argument (offset < 0).

Common situations: Off-by-one in UI arithmetic; user typed a minus sign; default value misconfigured to -1.

Related errors


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