{"record":{"id":"d52b7b5a6335deb0","repo":"gchq/CyberChef","slug":"incorrect-number-of-samples","errorCode":null,"errorMessage":"Incorrect number of samples.","messagePattern":"Incorrect number of samples\\.","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/CompareCTPHHashes.mjs","lineNumber":46,"sourceCode":"        this.inputType = \"string\";\n        this.outputType = \"Number\";\n        this.args = [\n            {\n                \"name\": \"Delimiter\",\n                \"type\": \"option\",\n                \"value\": HASH_DELIM_OPTIONS\n            }\n        ];\n    }\n\n    /**\n     * @param {string} input\n     * @param {Object[]} args\n     * @returns {Number}\n     */\n    run(input, args) {\n        const samples = input.split(Utils.charRep(args[0]));\n        if (samples.length !== 2) throw new OperationError(\"Incorrect number of samples.\");\n        return ctphjs.similarity(samples[0], samples[1]);\n    }\n\n}\n\nexport default CompareCTPHHashes;\n","sourceCodeStart":28,"sourceCodeEnd":53,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/CompareCTPHHashes.mjs#L28-L53","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Provide exactly two CTPH hashes separated by exactly one occurrence of the selected delimiter.","Pick the delimiter option that matches how your two hashes are actually separated.","Trim surrounding whitespace and remove stray delimiters so the split yields precisely two non-empty samples."],"exampleFix":"// before (input has one hash)\ninput = \"3:AXhF:AXhF\";\n// after (two hashes, newline-separated, delimiter = Line feed)\ninput = \"3:AXhF:AXhF\\n24:ABCD:ABCD\";","handlingStrategy":"validation","validationCode":"import Utils from \"src/core/Utils.mjs\";\nconst delim = Utils.charRep(delimiterOption);\nconst samples = input.split(delim);\nif (samples.length !== 2) {\n  throw new Error(`Expected exactly 2 CTPH hashes, got ${samples.length}`);\n}\nreturn samples;","typeGuard":"function isTwoSamples(input, delim) {\n  return input.split(delim).length === 2;\n}","tryCatchPattern":null,"preventionTips":["Confirm the delimiter option matches the real separator in your data before comparing.","Strip stray delimiters and surrounding whitespace so the split yields exactly two non-empty hashes.","If a hash internally contains the delimiter, switch to a delimiter that does not appear in the hash text."],"tags":["cyberchef","fuzzy-hash","ctph","input-validation","operation-error"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}