Module: Buckets
- Defined in:
- lib/tlsh/buckets.rb
Overview
Buckets provides meat functionality of the TLSH algorithm bucketing
Constant Summary collapse
- WINDOW_LENGTH =
5
- NUM_BUCKETS =
256
- CODE_SIZE =
32
- SALT =
[2, 3, 5, 7, 11, 13].freeze
Class Method Summary collapse
Class Method Details
.buckets_binary(buckets, q1, q2, q3) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/tlsh/buckets.rb', line 9 def buckets_binary(buckets, q1, q2, q3) bin_hash = [] (0..CODE_SIZE - 1).each do |i| h = 0 (0..3).each do |j| k = buckets[4 * i + j] h += addition(q1, q2, q3, j, k) bin_hash[CODE_SIZE - 1 - i] = h end end bin_hash end |
.fill_buckets(input) ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/tlsh/buckets.rb', line 24 def fill_buckets(input) # ensure we have an array (not enumerable) input = input.to_a if input.is_a?(Enumerable) chunk_slice = input[0..WINDOW_LENGTH - 1].compact chunk = chunk_slice[0..5].dup chunk.reverse! fill_buckets_looping(input, chunk_slice.size, chunk) end |