Compare commits
No commits in common. "5eeb46c4b41aa779dfaeafb6803f0929a81cba95" and "13bcfbbafdf49bf5a44db65e094c229ade629f68" have entirely different histories.
5eeb46c4b4
...
13bcfbbafd
3 changed files with 5 additions and 4 deletions
|
@ -12,7 +12,7 @@ def hash_gen(s: str, h: int, mult: int):
|
||||||
cur ^= (cur >> 16)
|
cur ^= (cur >> 16)
|
||||||
cur = (cur * 0x85ebca6b) & MASK32
|
cur = (cur * 0x85ebca6b) & MASK32
|
||||||
cur ^= (cur >> 13)
|
cur ^= (cur >> 13)
|
||||||
print(f"Hash: {cur:#010x}")
|
print(f"String: {s!r} Hash: {cur:#010x}")
|
||||||
h = cur
|
h = cur
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
|
|
|
@ -7,12 +7,12 @@ def ds_gen(dsize):
|
||||||
"""Generate random strings dataset"""
|
"""Generate random strings dataset"""
|
||||||
dataset = []
|
dataset = []
|
||||||
for _ in range(dsize):
|
for _ in range(dsize):
|
||||||
length = random.randint(500000, 1000000)
|
length = random.randint(10, 50)
|
||||||
random_string = ''.join(random.choices(string.ascii_letters + string.digits, k=length))
|
random_string = ''.join(random.choices(string.ascii_letters + string.digits, k=length))
|
||||||
dataset.append(random_string)
|
dataset.append(random_string)
|
||||||
return dataset
|
return dataset
|
||||||
|
|
||||||
def hash_benchmark(dataset, hash_func):
|
def hash_benchmark(dataset, hash_func, hash_name):
|
||||||
"""Benchmark hashing function and detect collisions"""
|
"""Benchmark hashing function and detect collisions"""
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
hashes = {}
|
hashes = {}
|
||||||
|
@ -43,7 +43,7 @@ def main():
|
||||||
print(f"Testing with {len(dataset)} strings\n")
|
print(f"Testing with {len(dataset)} strings\n")
|
||||||
|
|
||||||
for hash_func, name in hash_functions:
|
for hash_func, name in hash_functions:
|
||||||
time_taken, collision_count, collisions = hash_benchmark(dataset, hash_func)
|
time_taken, collision_count, collisions = hash_benchmark(dataset, hash_func, name)
|
||||||
print(f"{name}:")
|
print(f"{name}:")
|
||||||
print(f" Time: {time_taken:.6f} seconds")
|
print(f" Time: {time_taken:.6f} seconds")
|
||||||
print(f" Collisions: {collision_count}")
|
print(f" Collisions: {collision_count}")
|
||||||
|
|
|
@ -13,6 +13,7 @@ def elgamal_keygen(bits: int = 512) -> Tuple[Tuple[int, int, int], int]:
|
||||||
h = pow(g, x, p)
|
h = pow(g, x, p)
|
||||||
return (p, g, h), x
|
return (p, g, h), x
|
||||||
|
|
||||||
|
|
||||||
def elgamal_encrypt(message: bytes, pub_key: Tuple[int, int, int]) -> Tuple[int, int]:
|
def elgamal_encrypt(message: bytes, pub_key: Tuple[int, int, int]) -> Tuple[int, int]:
|
||||||
p, g, h = pub_key
|
p, g, h = pub_key
|
||||||
m = int.from_bytes(message, "big")
|
m = int.from_bytes(message, "big")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue