之前我发了这个帖子分析 OpenAI-Sentinel-Proof-Token 生成算法,不过还是有人说不会生成。
这有何难,把代码丢给GPT让它翻译就好了。下面是我用GPT翻译的Python版本,亲测生成正确。
import base64
import hashlib
import json
import random
from datetime import datetime, timedelta
class ChatGPTPoW:
def get_answer(self, payload):
if payload and 'seed' in payload and 'difficulty' in payload and 'user_agent' in payload:
seed = payload['seed']
user_agent = payload['user_agent']
difficulty = payload['difficulty']
if isinstance(seed, str) and isinstance(difficulty, str):
return "gAAAAAB" + self._generate_answer(seed, difficulty, user_agent)
return None
def _generate_answer(self, seed, difficulty, user_agent):
wh = random.randint(1000, 3000)
config = self._get_config(wh, user_agent)
difficulty_len = len(difficulty)
for attempt in range(100000):
config[3] = attempt
json_str = json.dumps(config, ensure_ascii=False, separators=(',', ':'))
answer = base64.b64encode(json_str.encode('utf-8'))
candidate = self._hash_function(seed, answer)
if candidate[:difficulty_len] <= difficulty:
return answer.decode('utf-8')
@staticmethod
def _get_config(wh, user_agent):
now_utc = datetime.utcnow()
china_offset = timedelta(hours=8)
now_china = now_utc + china_offset
formatted_time = now_china.strftime(f'%a %b %d %Y %H:%M:%S GMT+0800 (中国标准时间)')
return [
wh,
formatted_time,
None,
0,
user_agent
]
@staticmethod
def _hash_function(seed, answer):
hasher = hashlib.sha3_512()
encoded_input = seed.encode('utf-8') + answer
hasher.update(encoded_input)
return hasher.hexdigest()
chatgpt_pow = ChatGPTPoW()
print(chatgpt_pow.get_answer({
'seed': '0.8946898039931731',
'difficulty': '04b04f',
'user_agent': 'Mozilla/5.0 xxx'
}))
再拿5分,赢麻了。