publish new lyrics #162
Replies: 3 comments
-
|
Beta Was this translation helpful? Give feedback.
-
@JohnStyleZ Codeium fixed it ™️ import hashlib
import requests
# was just testing, didn't want to put strain on the official lrclib server,
# so I just got codeium to rewrite it in python.
def verify_answer(prefix: str, target: str, nonce: int):
input_str = prefix + str(nonce)
hashed_bytes = hashlib.sha256(input_str.encode()).digest()
target_bytes = bytes.fromhex(target)
if len(target_bytes) != len(hashed_bytes):
return False
for hashed_byte, target_byte in zip(hashed_bytes, target_bytes):
if hashed_byte > target_byte:
return False
if hashed_byte < target_byte:
break
return True
def solve_challenge(prefix, target_hex):
"""
Solve the challenge by iterating through possible nonce values until a valid one is found.
Args:
prefix (str): The prefix of the token to be hashed.
target_hex (str): The target hash value as a hexadecimal string.
Returns:
int: The nonce value that satisfies the challenge.
"""
nonce = 0
target = bytes.fromhex(target_hex)
print("Solving challenge...")
while True:
token = f"{prefix}:{nonce}".encode()
# print("Generated token:", token)
if verify_answer(prefix, target.hex(), nonce):
break
# print("Nonce not valid, incrementing...")
nonce += 1
print("Nonce found:", nonce)
return nonce
res = requests.post("https://lrclib.net/api/request-challenge")
json = res.json()
solution = solve_challenge(json["prefix"], json["target"])
token = f"{json['prefix']}:{solution}"
print("Token:", token)
# do something with the token |
Beta Was this translation helpful? Give feedback.
-
@JohnStyleZ uploaded it to Codeberg: https://codeberg.org/RealPacket/lrclib-challenge-solver-python/ (this account really is only for contributing to GitHub things, don't trust them with my main repos anymore after they suspended me out of nowhere, and I don't know why because I forgot to update my main email on GitHub to a different one because it was using skiff, and I was suspended way after August 9, 2024, so I can't view the skiff emails, I didn't have forwarding on either) |
Beta Was this translation helpful? Give feedback.
-
I tried to convert the rust file into python and integrate this into my Flask application. but i am keep getting {"message":"The provided publish token is incorrect","name":"IncorrectPublishTokenError","statusCode":400}.
can you take a look if i done something wrong?
def verify_nonce(result, target):
if len(result) != len(target):
return False
def solve_challenge(prefix, target_hex):
nonce = 0
target = bytes.fromhex(target_hex)
{'prefix': '4FriQWe2ZRUVTrd8HoV6ZxZ4QdkDZHdI', 'target': '000000FF00000000000000000000000000000000000000000000000000000000'}
x-publish-token: 4FriQWe2ZRUVTrd8HoV6ZxZ4QdkDZHdI:35093022
Beta Was this translation helpful? Give feedback.
All reactions