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,38 @@
import itertools
import string
from modes.hash_mode import HashMode
class CollisionsTest:
"""
Грубый поиск коллизий: перебираем строки до max_len
из заданного алфавита и проверяем, совпадут ли хэши.
"""
def run(self, variant: str, max_len: int = 3, alphabet: str = "alnum", bytes: int = 16) -> dict:
hasher = HashMode()
seen = {}
# выбор алфавита
if alphabet == "alnum":
chars = string.ascii_lowercase + string.digits
elif alphabet == "alpha":
chars = string.ascii_lowercase
elif alphabet == "digits":
chars = string.digits
else:
raise ValueError(f"Неизвестный алфавит: {alphabet}")
for length in range(1, max_len + 1):
for msg_tuple in itertools.product(chars, repeat=length):
msg = "".join(msg_tuple)
h = hasher.run(variant, msg, bytes=bytes)
if h in seen:
return {
"collision_found": True,
"hash": h,
"messages": [seen[h], msg],
}
seen[h] = msg
return {"collision_found": False}