Initial commit

This commit is contained in:
user
2026-07-12 14:06:45 +04:00
commit a75028d68f
148 changed files with 3275 additions and 0 deletions
@@ -0,0 +1,44 @@
import string
import random
from modes.hash_mode import HashMode
class UniformityAnalyzer:
"""
Анализ равномерности распределения хэшей.
"""
def run(self, variant: str, count: int = 100, buckets: int = 10, bytes: int = 16) -> dict:
hasher = HashMode()
alphabet = string.ascii_lowercase + string.digits
# случайные сообщения
messages = [
"".join(random.choice(alphabet)
for _ in range(random.randint(5, 10)))
for _ in range(count)
]
# хэши
hashes = [hasher.run(variant, msg, bytes=bytes) for msg in messages]
# берём первые 8 hex-символов → число
values = [int(h[:8], 16) for h in hashes]
values.sort()
# диапазоны
min_val, max_val = values[0], values[-1]
step = (max_val - min_val) / buckets if max_val > min_val else 1
distribution = [0] * buckets
for v in values:
idx = min(int((v - min_val) / step), buckets - 1)
distribution[idx] += 1
return {
"count": count,
"buckets": buckets,
"messages": messages,
"hashes": hashes,
"distribution": distribution,
}