gchq/CyberChef · error · OperationError

Incorrect number of samples.

Error message

Incorrect number of samples.

What it means

Compare CTPH Hashes compares two Context Triggered Piecewise Hashing (ctph/ssdeep-style) fuzzy hashes and returns a 0–100 similarity score. It splits the input string on the chosen delimiter (Utils.charRep(args[0])) and requires exactly two resulting samples, because ctphjs.similarity takes exactly two operands. The guard `if (samples.length !== 2)` rejects any other count.

Source

Thrown at src/core/operations/CompareCTPHHashes.mjs:46

        this.inputType = "string";
        this.outputType = "Number";
        this.args = [
            {
                "name": "Delimiter",
                "type": "option",
                "value": HASH_DELIM_OPTIONS
            }
        ];
    }

    /**
     * @param {string} input
     * @param {Object[]} args
     * @returns {Number}
     */
    run(input, args) {
        const samples = input.split(Utils.charRep(args[0]));
        if (samples.length !== 2) throw new OperationError("Incorrect number of samples.");
        return ctphjs.similarity(samples[0], samples[1]);
    }

}

export default CompareCTPHHashes;

View on GitHub (pinned to 4290ea7539)

Solutions

  1. Provide exactly two CTPH hashes separated by exactly one occurrence of the selected delimiter.
  2. Pick the delimiter option that matches how your two hashes are actually separated.
  3. Trim surrounding whitespace and remove stray delimiters so the split yields precisely two non-empty samples.

Example fix

// before (input has one hash)
input = "3:AXhF:AXhF";
// after (two hashes, newline-separated, delimiter = Line feed)
input = "3:AXhF:AXhF\n24:ABCD:ABCD";
Defensive patterns

Strategy: validation

Validate before calling

import Utils from "src/core/Utils.mjs";
const delim = Utils.charRep(delimiterOption);
const samples = input.split(delim);
if (samples.length !== 2) {
  throw new Error(`Expected exactly 2 CTPH hashes, got ${samples.length}`);
}
return samples;

Type guard

function isTwoSamples(input, delim) {
  return input.split(delim).length === 2;
}

Prevention

When it happens

Trigger: Input containing zero, one, or three+ hash samples after splitting; using a delimiter that does not match the actual separator in the data; empty input; stray extra delimiter characters producing an empty third field.

Common situations: Pasting only one hash; pasting three hashes by accident; choosing 'Line feed' delimiter when hashes are comma-separated (or vice versa); hash text itself containing the delimiter character.

Related errors


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