Module: Ssdeep::FuzzyComparable

Defined in:
lib/ssdeep.rb,
lib/russdeep.rb

Overview

The FuzzyComparable module adds mixins for doing fuzzy hash comparisons. The object extending must simply implement the ‘ssdeep’ method, which should return a string containing a fuzzy CTPH hash.

Instance Method Summary collapse

Instance Method Details

#fuzzy_match(other, threshold = 25) ⇒ Object

Returns true/false whether the sample matches a CTPH (fuzzy hash) with a score above a specified threshold

Parameters:

  • String,Object

    other The hash string or other object to compare to. If other is not a string, it just needs to implement the ‘ssdeep’ method.

  • Integer

    threshold The theshold above-which a match is considered true. If a threshold is supplied above 100, it is treated as 100.

Returns:

  • true,false Whether a match occurred.



46
47
48
# File 'lib/ssdeep.rb', line 46

def fuzzy_match(other, threshold=25)
  return (fuzzy_score(other) >= [threshold, 100].min)
end

#fuzzy_score(other) ⇒ Object

Returns a CTPH comparison score between this object and another’s fuzzy hash.

Parameters:

  • String,Object

    other The hash string or other object to compare to. If other is not a string, it just needs to implement the ‘ssdeep’ method.



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ssdeep.rb', line 20

def fuzzy_score(other)
  other_hash=
    if other.is_a? String
      other
    elsif other.respond_to? :ssdeep
      other.ssdeep
    else
      raise(TypeError, "can't handle type for other: #{other.class}")
    end

  Ssdeep.compare(self.ssdeep, other_hash)
end