devicer.py 0.1.5__tar.gz → 0.2.0__tar.gz
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.
- {devicer_py-0.1.5 → devicer_py-0.2.0}/PKG-INFO +1 -1
- {devicer_py-0.1.5 → devicer_py-0.2.0}/pyproject.toml +1 -1
- devicer_py-0.2.0/src/devicer/confidence.py +99 -0
- {devicer_py-0.1.5 → devicer_py-0.2.0}/src/devicer.py.egg-info/PKG-INFO +1 -1
- devicer_py-0.1.5/src/devicer/confidence.py +0 -53
- {devicer_py-0.1.5 → devicer_py-0.2.0}/README.md +0 -0
- {devicer_py-0.1.5 → devicer_py-0.2.0}/license.txt +0 -0
- {devicer_py-0.1.5 → devicer_py-0.2.0}/setup.cfg +0 -0
- {devicer_py-0.1.5 → devicer_py-0.2.0}/src/devicer/__init__.py +0 -0
- {devicer_py-0.1.5 → devicer_py-0.2.0}/src/devicer/hashing.py +0 -0
- {devicer_py-0.1.5 → devicer_py-0.2.0}/src/devicer.py.egg-info/SOURCES.txt +0 -0
- {devicer_py-0.1.5 → devicer_py-0.2.0}/src/devicer.py.egg-info/dependency_links.txt +0 -0
- {devicer_py-0.1.5 → devicer_py-0.2.0}/src/devicer.py.egg-info/requires.txt +0 -0
- {devicer_py-0.1.5 → devicer_py-0.2.0}/src/devicer.py.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: devicer.py
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.2.0
|
4
4
|
Summary: Open-Source Python Middleware for Digital Fingerprinting
|
5
5
|
Author: One anonymous contributor
|
6
6
|
Author-email: Samuel Roux <sam.roux.com@gmail.com>, Stephen Perso <stephenrperso@gmail.com>
|
@@ -6,7 +6,7 @@ requires = [
|
|
6
6
|
build-backend = "setuptools.build_meta"
|
7
7
|
[project]
|
8
8
|
name = "devicer.py"
|
9
|
-
version = "0.
|
9
|
+
version = "0.2.0"
|
10
10
|
authors = [
|
11
11
|
{name = "Samuel Roux", email = "sam.roux.com@gmail.com"},
|
12
12
|
{name = "Stephen Perso", email = "stephenrperso@gmail.com"},
|
@@ -0,0 +1,99 @@
|
|
1
|
+
from .hashing import get_tlsh_hash, get_hash_difference
|
2
|
+
import math
|
3
|
+
|
4
|
+
def compare_lists(data1: list, data2: list, max_depth: int = 5) -> tuple[int, int]:
|
5
|
+
"""
|
6
|
+
Compare two lists and return the count of matching elements and total elements.
|
7
|
+
|
8
|
+
Args:
|
9
|
+
data1 (list): First list containing data.
|
10
|
+
data2 (list): Second list containing data.
|
11
|
+
max_depth (int): Maximum depth to compare nested lists. Default is 5.
|
12
|
+
|
13
|
+
Returns:
|
14
|
+
tuple: A tuple containing the count of matching elements and total elements compared.
|
15
|
+
"""
|
16
|
+
fields = 0
|
17
|
+
matches = 0
|
18
|
+
|
19
|
+
if max_depth <= 0:
|
20
|
+
return matches, fields
|
21
|
+
|
22
|
+
sorted_data1 = sorted(data1, key=lambda x: str(x) if isinstance(x, (dict, list)) else x)
|
23
|
+
sorted_data2 = sorted(data2, key=lambda x: str(x) if isinstance(x, (dict, list)) else x)
|
24
|
+
|
25
|
+
max_length = min(len(data1), len(data2))
|
26
|
+
for i in range(max_length):
|
27
|
+
if sorted_data1[i] and sorted_data2[i]:
|
28
|
+
fields += 1
|
29
|
+
if isinstance(sorted_data1[i], list) and isinstance(sorted_data2[i], list):
|
30
|
+
sub_matches, sub_fields = compare_lists(sorted_data1[i], sorted_data2[i], max_depth - 1)
|
31
|
+
fields += sub_fields - 1
|
32
|
+
matches += sub_matches
|
33
|
+
elif isinstance(sorted_data1[i], dict) and isinstance(sorted_data2[i], dict):
|
34
|
+
sub_matches, sub_fields = compare_dictionaries(sorted_data1[i], sorted_data2[i], max_depth - 1)
|
35
|
+
fields += sub_fields - 1
|
36
|
+
matches += sub_matches
|
37
|
+
if sorted_data1[i] in sorted_data2:
|
38
|
+
matches += 1
|
39
|
+
return matches, fields
|
40
|
+
|
41
|
+
def compare_dictionaries(data1: dict, data2: dict, max_depth: int = 5) -> tuple[int, int]:
|
42
|
+
"""
|
43
|
+
Compare two dictionaries and return the count of matching fields and total fields.
|
44
|
+
|
45
|
+
Args:
|
46
|
+
data1 (dict): First dictionary containing data.
|
47
|
+
data2 (dict): Second dictionary containing data.
|
48
|
+
max_depth (int): Maximum depth to compare nested dictionaries. Default is 5.
|
49
|
+
|
50
|
+
Returns:
|
51
|
+
tuple: A tuple containing the count of matching fields and total fields compared.
|
52
|
+
"""
|
53
|
+
fields = 0
|
54
|
+
matches = 0
|
55
|
+
|
56
|
+
if max_depth <= 0:
|
57
|
+
return matches, fields
|
58
|
+
|
59
|
+
for key in data1:
|
60
|
+
if key in data2:
|
61
|
+
fields += 1
|
62
|
+
if isinstance(data1[key], dict) and isinstance(data2[key], dict):
|
63
|
+
sub_matches, sub_fields = compare_dictionaries(data1[key], data2[key], max_depth - 1)
|
64
|
+
fields += sub_fields - 1
|
65
|
+
matches += sub_matches
|
66
|
+
elif isinstance(data1[key], list) and isinstance(data2[key], list):
|
67
|
+
sub_matches, sub_fields = compare_lists(data1[key], data2[key], max_depth - 1)
|
68
|
+
fields += sub_fields - 1
|
69
|
+
matches += sub_matches
|
70
|
+
if data1[key] == data2[key]:
|
71
|
+
matches += 1
|
72
|
+
return matches, fields
|
73
|
+
|
74
|
+
def calculate_confidence(data1: dict, data2: dict) -> float:
|
75
|
+
"""
|
76
|
+
Calculate the confidence score based on two dictionaries of data.
|
77
|
+
|
78
|
+
Args:
|
79
|
+
data1 (dict): First dictionary containing data.
|
80
|
+
data2 (dict): Second dictionary containing data.
|
81
|
+
|
82
|
+
Returns:
|
83
|
+
float: Confidence score calculated as the ratio of the sum of values in data1 to the sum of values in data2.
|
84
|
+
"""
|
85
|
+
matches, fields = compare_dictionaries(data1, data2)
|
86
|
+
|
87
|
+
if fields == 0 or matches == 0:
|
88
|
+
return 0
|
89
|
+
|
90
|
+
hash1 = get_tlsh_hash(str(data1).encode('utf-8'))
|
91
|
+
hash2 = get_tlsh_hash(str(data2).encode('utf-8'))
|
92
|
+
difference_score = get_hash_difference(hash1, hash2)
|
93
|
+
|
94
|
+
inverse_match_score = 1 - (matches / fields)
|
95
|
+
x = 1.3 * difference_score * inverse_match_score
|
96
|
+
if (inverse_match_score == 0 or difference_score == 0):
|
97
|
+
return 100
|
98
|
+
confidence_score = 100 / (1 + math.e ** (-4.5 + (0.3 * x)))
|
99
|
+
return confidence_score
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: devicer.py
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.2.0
|
4
4
|
Summary: Open-Source Python Middleware for Digital Fingerprinting
|
5
5
|
Author: One anonymous contributor
|
6
6
|
Author-email: Samuel Roux <sam.roux.com@gmail.com>, Stephen Perso <stephenrperso@gmail.com>
|
@@ -1,53 +0,0 @@
|
|
1
|
-
from .hashing import get_tlsh_hash, get_hash_difference
|
2
|
-
import math
|
3
|
-
|
4
|
-
def compare_dictionaries(data1: dict, data2: dict) -> tuple[int, int]:
|
5
|
-
"""
|
6
|
-
Compare two dictionaries and return the count of matching fields and total fields.
|
7
|
-
|
8
|
-
Args:
|
9
|
-
data1 (dict): First dictionary containing data.
|
10
|
-
data2 (dict): Second dictionary containing data.
|
11
|
-
|
12
|
-
Returns:
|
13
|
-
tuple: A tuple containing the count of matching fields and total fields compared.
|
14
|
-
"""
|
15
|
-
fields = 0
|
16
|
-
matches = 0
|
17
|
-
for key in data1:
|
18
|
-
if key in data2:
|
19
|
-
fields += 1
|
20
|
-
if isinstance(data1[key], dict) and isinstance(data2[key], dict):
|
21
|
-
sub_matches, sub_fields = compare_dictionaries(data1[key], data2[key])
|
22
|
-
matches += sub_matches
|
23
|
-
fields += sub_fields - 1 # Subtract 1 to avoid double counting the key
|
24
|
-
elif data1[key] == data2[key]:
|
25
|
-
matches += 1
|
26
|
-
return matches, fields
|
27
|
-
|
28
|
-
def calculate_confidence(data1: dict, data2: dict) -> float:
|
29
|
-
"""
|
30
|
-
Calculate the confidence score based on two dictionaries of data.
|
31
|
-
|
32
|
-
Args:
|
33
|
-
data1 (dict): First dictionary containing data.
|
34
|
-
data2 (dict): Second dictionary containing data.
|
35
|
-
|
36
|
-
Returns:
|
37
|
-
float: Confidence score calculated as the ratio of the sum of values in data1 to the sum of values in data2.
|
38
|
-
"""
|
39
|
-
matches, fields = compare_dictionaries(data1, data2)
|
40
|
-
|
41
|
-
if fields == 0 or matches == 0:
|
42
|
-
return 0
|
43
|
-
|
44
|
-
hash1 = get_tlsh_hash(str(data1).encode('utf-8'))
|
45
|
-
hash2 = get_tlsh_hash(str(data2).encode('utf-8'))
|
46
|
-
difference_score = get_hash_difference(hash1, hash2)
|
47
|
-
|
48
|
-
inverse_match_score = 1 - (matches / fields)
|
49
|
-
x = difference_score * inverse_match_score
|
50
|
-
if (inverse_match_score == 0 or difference_score == 0):
|
51
|
-
return 100
|
52
|
-
confidence_score = 100 / (1 + math.e ** (-4.5 + (0.25 * x)))
|
53
|
-
return confidence_score
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|