使用 Python 生成 OpenAI-Sentinel-Proof-Token

之前我发了这个帖子分析 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分,赢麻了。

106 个赞

前排前排

疯狂上分

好好好,又快又好

前排

前排

前排

始皇无敌

不止5分,却只砍了5分!

太快了

太强了吧!这。。。。。。。。。。。。。。。

好,第一没有了

始皇威武(5),我赏心悦耳(2)

既然如此那就手拿2分

本想丢的 奈何杀出了个秦始皇 :zipper_mouth_face:

有没有极端情况下,算的值都不满足条件的情况呢?,概率很小但存在那种

2分

借助AI狂砍5分~

用GPT来欺负GPT

1 个赞

现在的 difficulty 值很容易,不会算不出的。

2 个赞