用GPU计算python

2024-10-06 06:56:50 发布

您现在位置:Python中文网/ 问答频道 /正文

我有以下python脚本。我想知道是否有任何机会,它可以调整使用gpu计算能力。作用:使用秘密.令牌(32)函数,然后它将其应用于一组具有已知结果的已定义规则,如果它与所有规则匹配,则将匹配的哈希输出到一个文件中,否则将在另一个文件中写入错误的哈希。我想用gpu来做这件事,以获得更快的计算速度。谨致问候。在

import random
import hashlib
import secrets

def writeFile(addString):
    txtFile = open("NOTFOUND.txt", 'a')
    txtFile.write(addString)
    txtFile.close()

if __name__ == "__main__":
    whileLoopBreak = True
    txtFileRead = open("NOTFOUND.txt", 'a')
    checkIfExist = 0
    public_seed = 3314371705
    roundList = ['1176881', '1176882', '1176883', '1176884', '1176885']
    while whileLoopBreak:
        tempString = secrets.token_hex(32)
        txtFileRead = open("NOTFOUND.txt", 'r')
        for line in txtFileRead:
            while tempString == line[0:-1]:
                if(tempString != line[0:-1]):
                    break
                tempString = secrets.token_hex(32)
        txtFileRead.close()
        writeFile(tempString + "\n")
        for i in range(0, 5):
            hashString = tempString + "-" + str(public_seed) + "-" + roundList[i]
            hash_object = hashlib.sha256(hashString.encode())
            hex_dig = hash_object.hexdigest()
            begToEnd = hex_dig[0:8]
            intFromBTE = int(begToEnd, 16) % 15
            if intFromBTE == 10 and roundList[i] == roundList[0]:##1
                checkIfExist += 1
            elif intFromBTE == 4 and roundList[i] == roundList[1]:##2
                checkIfExist += 1
            elif intFromBTE == 12 and roundList[i] == roundList[2]:##3
                checkIfExist += 1
            elif intFromBTE == 6 and roundList[i] == roundList[3]:##4
                checkIfExist += 1
            elif intFromBTE == 8 and roundList[i] == roundList[4]:##5
                checkIfExist += 1  
        if checkIfExist == 5:
            checkIfExist = 0
            txtFile = open("serverSeedFound.txt", 'a')
            txtFile.write(tempString + "\n")
            print(tempString)
            txtFile.close()
        else:
            checkIfExist = 0

Tags: andimporttxtifopensecretshexelif