# 随机钱包私钥源码 **Published by:** [punk2898 🙌💎](https://paragraph.com/@2898punk/) **Published on:** 2023-04-17 **URL:** https://paragraph.com/@2898punk/dlELSr7Pg5MVIaM7sit2 ## Content 当然上述的玩法仅供娱乐 假设你的算力水平每秒 900 万个比特币地址 即每秒约 2^23 个比特币地址 暴力破解需要花掉的时间就是 2^(160-23) = 2^137 秒! 换算之后超过 1024 年! import random from web3 import Web3 from mnemonic import Mnemonic # 使用BIP39单词列表 mnemo = Mnemonic("english") # 使用Web3连接以太坊网络 w3 = Web3(Web3.HTTPProvider('https://mainnet.infura.io/v3/xxxx')) # 设置一个助记词变量和一个余额变量 seed_phrase = "" balance = 0 # 当余额为0时,持续生成助记词并检查余额 while balance == 0: # 随机生成一个12个单词的助记词 # seed_phrase = mnemo.generate(128) seed_phrase = mnemo.generate(strength=256) # 将助记词转换为私钥 private_key = mnemo.to_entropy(seed_phrase) # 将私钥转换为地址 address = w3.to_checksum_address(w3.eth.account.from_key(private_key).address) # 检查余额 # balance = w3.eth.getBalance(address) balance = w3.eth.get_balance(address) # 打印地址和余额 print("Address:", address, "Balance:", w3.from_wei(balance, 'ether')) # 如果找到了余额,则打印助记词 print("Seed phrase:", seed_phrase) ## Publication Information - [punk2898 🙌💎](https://paragraph.com/@2898punk/): Publication homepage - [All Posts](https://paragraph.com/@2898punk/): More posts from this publication - [RSS Feed](https://api.paragraph.com/blogs/rss/@2898punk): Subscribe to updates - [Twitter](https://twitter.com/dily_xz): Follow on Twitter