kit
kit
PDProgram Dream
Created by kit on 4/11/2025 in #🔨┃dev-logs
Hashgate - simple PoW/Hashcash-like spam protection algorithm for centralised systems
"""
Hashgate Algorithm.
It's just a preimage puzzle with lookup-table defence.

1. The server generates the key, the code and the hash, where:
hash = SHA256(challenge + key)

The challenge and the key are measured in bytes.

The challenge is preferably 16 bytes.
The key is the "difficulty", which rises exponentially.

2. The server sends the challenge and the hash to the user

3. The user can now calculate the key to access the server
"""

import hashlib
import secrets
import itertools


def sha256(data: bytes) -> bytes:
"""A wrapper function for SHA256"""
return hashlib.sha256(data).digest()


# It doesn't matter how long the "challenge" is.
# And it makes the algorithm secure from look-up tables!
# There shouldn't be any significant computational impact.
# The purpose is to make the algorithm secure from lookup tables.
# 16 bytes (128 bits) would be enough to make it practically unique.
challenge = secrets.token_bytes(16)

# And this thing sets the difficulty:
# I think 3 bytes would be okay, but enough to stop spam.
KEY_LENGTH = 3
key = secrets.token_bytes(KEY_LENGTH)

hashgate = sha256(challenge + key)

# Let's try to brute-force it now xD

print(f"Challenge: {challenge.hex()}")
print(f"Key: {key.hex()}")
print(f"Hash: {hashgate.hex()}")
for guess in itertools.product(range(256), repeat=KEY_LENGTH):
guess_key = bytes(guess)
guess_hash = sha256(challenge + guess_key)
if guess_hash == hashgate:
print(f"Found key: {guess_key.hex()}")
break
"""
Hashgate Algorithm.
It's just a preimage puzzle with lookup-table defence.

1. The server generates the key, the code and the hash, where:
hash = SHA256(challenge + key)

The challenge and the key are measured in bytes.

The challenge is preferably 16 bytes.
The key is the "difficulty", which rises exponentially.

2. The server sends the challenge and the hash to the user

3. The user can now calculate the key to access the server
"""

import hashlib
import secrets
import itertools


def sha256(data: bytes) -> bytes:
"""A wrapper function for SHA256"""
return hashlib.sha256(data).digest()


# It doesn't matter how long the "challenge" is.
# And it makes the algorithm secure from look-up tables!
# There shouldn't be any significant computational impact.
# The purpose is to make the algorithm secure from lookup tables.
# 16 bytes (128 bits) would be enough to make it practically unique.
challenge = secrets.token_bytes(16)

# And this thing sets the difficulty:
# I think 3 bytes would be okay, but enough to stop spam.
KEY_LENGTH = 3
key = secrets.token_bytes(KEY_LENGTH)

hashgate = sha256(challenge + key)

# Let's try to brute-force it now xD

print(f"Challenge: {challenge.hex()}")
print(f"Key: {key.hex()}")
print(f"Hash: {hashgate.hex()}")
for guess in itertools.product(range(256), repeat=KEY_LENGTH):
guess_key = bytes(guess)
guess_hash = sha256(challenge + guess_key)
if guess_hash == hashgate:
print(f"Found key: {guess_key.hex()}")
break
4 replies
PDProgram Dream
Created by kit on 1/2/2025 in #🔨┃dev-logs
Pyliblang - a simple localization library
https://gitlab.com/kirz/pyliblang I just was so tired of gettext.py, that i implemented my own library. Differences from gettext: 1) It uses .json files instead of .mo files 2) It supports Unicode by default 3) It's just easier to use than gettext. You don't need to do extra steps (format messages etc), it just works! Planned features: 1) Plurals 2) Meta-information (license, translation date, translation author ...) If you like the idea, I will package it properly and try to release on PyPI!
1 replies
PDProgram Dream
Created by kit on 11/21/2024 in #🔨┃dev-logs
New data serialization format. Curious what you think
44 replies