CompareSSDEEPHashes.mjs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /**
  2. * @author n1474335 [n1474335@gmail.com]
  3. * @copyright Crown Copyright 2016
  4. * @license Apache-2.0
  5. */
  6. import Operation from "../Operation";
  7. import Utils from "../Utils";
  8. import {HASH_DELIM_OPTIONS} from "../lib/Delim";
  9. import ssdeepjs from "ssdeep.js";
  10. import OperationError from "../errors/OperationError";
  11. /**
  12. * Compare SSDEEP hashes operation
  13. */
  14. class CompareSSDEEPHashes extends Operation {
  15. /**
  16. * CompareSSDEEPHashes constructor
  17. */
  18. constructor() {
  19. super();
  20. this.name = "Compare SSDEEP hashes";
  21. this.module = "Crypto";
  22. this.description = "Compares two SSDEEP fuzzy hashes to determine the similarity between them on a scale of 0 to 100.";
  23. this.infoURL = "https://forensicswiki.org/wiki/Ssdeep";
  24. this.inputType = "string";
  25. this.outputType = "Number";
  26. this.args = [
  27. {
  28. "name": "Delimiter",
  29. "type": "option",
  30. "value": HASH_DELIM_OPTIONS
  31. }
  32. ];
  33. }
  34. /**
  35. * @param {string} input
  36. * @param {Object[]} args
  37. * @returns {Number}
  38. */
  39. run(input, args) {
  40. const samples = input.split(Utils.charRep(args[0]));
  41. if (samples.length !== 2) throw new OperationError("Incorrect number of samples.");
  42. return ssdeepjs.similarity(samples[0], samples[1]);
  43. }
  44. }
  45. export default CompareSSDEEPHashes;