gchq/CyberChef · error · OperationError

Invalid input

Error message

Invalid input

What it means

Thrown by From BCD when a parsed nibble is NaN, i.e. parseInt(substr(i,4), 2) could not parse 4 characters as binary. This happens in Nibbles/Bytes input format when the input contains characters other than 0 and 1 (or whitespace). The check runs per nibble during value assembly.

Source

Thrown at src/core/operations/FromBCD.mjs:112

        if (!packed) {
            // Discard each high nibble
            for (let i = 0; i < nibbles.length; i++) {
                nibbles.splice(i, 1); // lgtm [js/loop-iteration-skipped-due-to-shifting]
            }
        }

        if (signed) {
            const sign = nibbles.pop();
            if (sign === 13 ||
                sign === 11) {
                // Negative
                output += "-";
            }
        }

        nibbles.forEach(n => {
            if (isNaN(n)) throw new OperationError("Invalid input");
            const val = encoding.indexOf(n);
            if (val < 0) throw new OperationError(`Value ${Utils.bin(n, 4)} is not in the encoding scheme`);
            output += val.toString();
        });

        return new BigNumber(output);
    }

}

export default FromBCD;

View on GitHub (pinned to 4290ea7539)

Solutions

  1. Set Input format to match the data: use 'Nibbles'/'Bytes' only for pure 0/1 binary strings.
  2. For hex or raw data, switch Input format to 'Raw'.
  3. Strip any non-binary characters before this op if the data is genuinely binary.

Example fix

// before: hex data fed as Nibbles
fromBcd.run('FFAA', ['8 4 2 1', true, false, 'Nibbles']) // parseInt('FFAA',2) -> NaN
// after: use Raw format
fromBcd.run('FFAA', ['8 4 2 1', true, false, 'Raw'])
Defensive patterns

Strategy: validation

Validate before calling

// For Nibbles/Bytes format, ensure the string is pure binary (0/1 + whitespace) first
if ((inputFormat === 'Nibbles' || inputFormat === 'Bytes') && !/^[01\s]+$/.test(input)) {
  // switch to Raw or clean the input; do not call fromBcd.run()
}

Type guard

function isBinaryNibbleString(s) {
  return /^[01\s]+$/.test(s);
}

Try / catch

try {
  fromBcd.run(input, args);
} catch (e) {
  if (e.type === 'OperationError' && e.message === 'Invalid input') {
    // input has non-binary chars for Nibbles/Bytes; switch Input format to Raw
  } else throw e;
}

Prevention

When it happens

Trigger: Input format set to 'Nibbles' or 'Bytes' but the input string contains hex digits, letters, or other non-binary characters; a nibble group like '2abc' that cannot parseInt as base 2; malformed spacing splitting into a non-4-char group.

Common situations: Mismatch between the selected Input format and the actual data (e.g. hex data fed as Nibbles); copy-paste introducing non-binary chars; partial/typo'd binary string.

Related errors


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