Fix: Updated salt generation to be alphanumeric in pow_generator.py

main
TiredFromTelehack 2024-10-18 02:57:39 +02:00
parent a95fc486b1
commit d237d14062
1 changed files with 14 additions and 21 deletions

View File

@ -1,27 +1,20 @@
import os
import base64
import random import random
import string
def generate_salt(length=16): def generate_salt(length=16):
"""Generate a URL-safe base64-encoded random salt.""" # Generate a salt with alphanumeric characters (A-Z, a-z, 0-9)
salt = os.urandom(length) # Generate random bytes return 'SALT' + ''.join(random.choices(string.ascii_letters + string.digits, k=length))
return "SALTE" + base64.urlsafe_b64encode(salt).decode('utf-8')[:12] # Prefix "SALTE" and limit the length
def generate_pow_code(): def generate_proof_of_work():
"""Generate a proof of work challenge code with randomized parameters.""" # Randomize memory cost, time cost, and difficulty
# Randomize memory cost (between 1 and 262144 bytes) memory_cost = random.randint(1, 262144) # Up to 262144
memory_cost = random.randint(1, 262144) # in bytes time_cost = 1 # Always set to 1
# Set time cost to 1 salt = generate_salt()
time_cost = 1 difficulty = random.randint(1000, 1500) # Between 1000 and 1500
# Generate a random salt
salt = generate_salt() # Generate the salt # Format the challenge code
# Randomize difficulty (between 1000 and 1500) proof_of_work_code = f"{memory_cost}:{time_cost}:{salt}:{difficulty}"
difficulty = random.randint(1000, 1500) # Random difficulty print(f"Generated Proof of Work Code: {proof_of_work_code}")
# Format the proof of work code
pow_code = f"{memory_cost}:{time_cost}:{salt}:{difficulty}"
return pow_code
if __name__ == "__main__": if __name__ == "__main__":
pow_code = generate_pow_code() generate_proof_of_work()
print("Generated Proof of Work Code:", pow_code)