hash_comparator 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 550a7997f98003e8493e13f2d57e532e1e25d337b071b9d1123142e946b3287e
|
4
|
+
data.tar.gz: d3f25227b786f9dfa2a14d313a46fe893a8590f875c6b063638fadc76b7278e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 063b599214283153a2fe2ab912a956426ccecabe943a74cd1727d5309c3440a737c93c5e10a188761bf11f5b09cb5c0c5a7db3d98d1c0b688085a611b2ca65c9
|
7
|
+
data.tar.gz: 0fe9b548064a7065108a14a43acfe1f086be64568a2323b8c0a6b82feb9ae6735389294fad70ac69aa9b5dbd7110a2d449a6a24038c1dc1cd6d3e634ff8671dd
|
@@ -6,35 +6,44 @@ require 'hash_comparator/reverse_matcher'
|
|
6
6
|
module HashComparator
|
7
7
|
module Emails
|
8
8
|
class Analyzer
|
9
|
-
def self.
|
9
|
+
def self.find_common_plaintext(hash_function:, subject_plaintext_emails:, target_hashed_emails:, options: {})
|
10
10
|
new(
|
11
11
|
hash_function: hash_function,
|
12
|
-
|
12
|
+
subject_plaintext_emails: subject_plaintext_emails,
|
13
13
|
target_hashed_emails: target_hashed_emails,
|
14
14
|
options: options
|
15
|
-
).
|
15
|
+
).find_common_plaintext
|
16
16
|
end
|
17
17
|
|
18
|
-
def self.find_common_hashes(hash_function:,
|
18
|
+
def self.find_common_hashes(hash_function:, subject_plaintext_emails:, target_hashed_emails:, options: {})
|
19
19
|
new(
|
20
20
|
hash_function: hash_function,
|
21
|
-
|
21
|
+
subject_plaintext_emails: subject_plaintext_emails,
|
22
22
|
target_hashed_emails: target_hashed_emails,
|
23
23
|
options: options
|
24
24
|
).find_common_hashes
|
25
25
|
end
|
26
26
|
|
27
|
-
def
|
27
|
+
def self.find_full_results(hash_function:, subject_plaintext_emails:, target_hashed_emails:, options: {})
|
28
|
+
new(
|
29
|
+
hash_function: hash_function,
|
30
|
+
subject_plaintext_emails: subject_plaintext_emails,
|
31
|
+
target_hashed_emails: target_hashed_emails,
|
32
|
+
options: options
|
33
|
+
).find_full_results
|
34
|
+
end
|
35
|
+
|
36
|
+
def initialize(hash_function:, subject_plaintext_emails:, target_hashed_emails:, options:)
|
28
37
|
@hash_function = hash_function
|
29
|
-
@
|
38
|
+
@subject_plaintext_emails = subject_plaintext_emails
|
30
39
|
@target_hashed_emails = target_hashed_emails
|
31
40
|
@options = options
|
32
41
|
@subject_hashed_emails = []
|
33
42
|
end
|
34
43
|
|
35
|
-
attr_accessor :hash_function, :
|
44
|
+
attr_accessor :hash_function, :subject_plaintext_emails, :subject_hashed_emails, :target_hashed_emails, :options
|
36
45
|
|
37
|
-
def
|
46
|
+
def find_common_plaintext
|
38
47
|
common_hashes = find_common_hashes
|
39
48
|
reverse_match(common_hashes)
|
40
49
|
end
|
@@ -45,18 +54,24 @@ module HashComparator
|
|
45
54
|
compare
|
46
55
|
end
|
47
56
|
|
57
|
+
def find_full_results
|
58
|
+
common_hashed_emails = find_common_hashes
|
59
|
+
common_plaintext_emails = reverse_match(common_hashed_emails)
|
60
|
+
{ common_hashed_emails: common_hashed_emails, common_plaintext_emails: common_plaintext_emails }
|
61
|
+
end
|
62
|
+
|
48
63
|
private
|
49
64
|
|
50
65
|
def parse
|
51
66
|
if options[:parsing]
|
52
|
-
@
|
67
|
+
@subject_plaintext_emails = Parser.parse(subject_plaintext_emails, options[:parsing])
|
53
68
|
end
|
54
69
|
end
|
55
70
|
|
56
71
|
def hash
|
57
72
|
@subject_hashed_emails = Hasher.hash(
|
58
73
|
hash_function: hash_function,
|
59
|
-
|
74
|
+
plaintext_items: subject_plaintext_emails
|
60
75
|
)
|
61
76
|
end
|
62
77
|
|
@@ -71,7 +86,7 @@ module HashComparator
|
|
71
86
|
ReverseMatcher.execute(
|
72
87
|
hash_function: hash_function,
|
73
88
|
hashed_items: common_hashes,
|
74
|
-
|
89
|
+
plaintext_items: subject_plaintext_emails
|
75
90
|
)
|
76
91
|
end
|
77
92
|
end
|
@@ -9,19 +9,19 @@ module HashComparator
|
|
9
9
|
sha512: Digest::SHA512
|
10
10
|
}.freeze
|
11
11
|
|
12
|
-
def self.hash(hash_function:,
|
13
|
-
new(hash_function: hash_function,
|
12
|
+
def self.hash(hash_function:, plaintext_items:)
|
13
|
+
new(hash_function: hash_function, plaintext_items: plaintext_items).hash
|
14
14
|
end
|
15
15
|
|
16
|
-
def initialize(hash_function:,
|
16
|
+
def initialize(hash_function:, plaintext_items:)
|
17
17
|
@hash_function = SUPPORTED_HASH_FUNCTIONS[hash_function]
|
18
|
-
@
|
18
|
+
@plaintext_items = plaintext_items
|
19
19
|
end
|
20
20
|
|
21
|
-
attr_accessor :hash_function, :
|
21
|
+
attr_accessor :hash_function, :plaintext_items
|
22
22
|
|
23
23
|
def hash
|
24
|
-
|
24
|
+
plaintext_items.map do |item|
|
25
25
|
hash_function.hexdigest(item)
|
26
26
|
end
|
27
27
|
end
|
@@ -3,29 +3,29 @@ require 'hash_comparator/hasher'
|
|
3
3
|
|
4
4
|
module HashComparator
|
5
5
|
class ReverseMatcher
|
6
|
-
def self.execute(hash_function:, hashed_items:,
|
6
|
+
def self.execute(hash_function:, hashed_items:, plaintext_items:)
|
7
7
|
new(
|
8
8
|
hash_function: hash_function,
|
9
9
|
hashed_items: hashed_items,
|
10
|
-
|
10
|
+
plaintext_items: plaintext_items
|
11
11
|
).execute
|
12
12
|
end
|
13
13
|
|
14
|
-
def initialize(hash_function:, hashed_items:,
|
14
|
+
def initialize(hash_function:, hashed_items:, plaintext_items:)
|
15
15
|
@hash_function = hash_function
|
16
|
-
@
|
16
|
+
@plaintext_items = plaintext_items
|
17
17
|
@hashed_items = hashed_items
|
18
18
|
end
|
19
19
|
|
20
|
-
attr_accessor :hash_function, :
|
20
|
+
attr_accessor :hash_function, :plaintext_items, :hashed_items
|
21
21
|
|
22
22
|
def execute
|
23
23
|
subject_hashed_items = Hasher.hash(
|
24
24
|
hash_function: hash_function,
|
25
|
-
|
25
|
+
plaintext_items: plaintext_items
|
26
26
|
)
|
27
27
|
|
28
|
-
matches =
|
28
|
+
matches = plaintext_items.each_with_index.each_with_object([]) do |(item, i), list|
|
29
29
|
list << item if hashed_items.include?(subject_hashed_items[i])
|
30
30
|
end
|
31
31
|
|