· 4 months ago · Jun 04, 2025, 08:10 PM
1#!/usr/bin/env python3
2
3# sudo apt install python3-pip
4# pip3 install hdwallet tqdm web3 bip32utils
5
6# 132x43 terminal size is recommended
7
8from hdwallet import HDWallet
9from hdwallet.cryptocurrencies import Bitcoin as BTC
10from hdwallet.hds import BIP32HD
11from hdwallet.mnemonics import BIP39Mnemonic
12from hdwallet.seeds import BIP39Seed
13from os import system, name
14from subprocess import check_output
15from tqdm import tqdm
16from web3 import Web3
17import base58
18import binascii
19import bip32utils
20import ecdsa
21import ecdsa.der
22import ecdsa.util
23import hashlib
24import math
25import mnemonic
26import os
27import pprint
28import random
29import re
30import requests
31import struct
32import unittest
33
34alchemy_url = "https://eth-mainnet.g.alchemy.com/v2/"
35
36def clear():
37 if name == 'nt':
38 _ = system('cls')
39 else:
40 _ = system('clear')
41 return
42
43def bw2wif1(s):
44 sha=hashlib.sha256(s.encode()).digest()
45 tmp=b'\x80'+sha
46 return base58.b58encode_check(tmp).decode()
47
48def bw2wifmany(i,o):
49 f1=open(i,'r')
50 cnt=sum(1 for line in open(i))
51 f2=open(o,'w')
52 for line in tqdm(f1, total=cnt, unit=" lines"):
53 x=line.rstrip('\n').encode()
54 sha=hashlib.sha256(x).digest()
55 tmp=b'\x80'+sha
56 h=base58.b58encode_check(tmp)
57 i=h+b" 0 # "+x+b'\n'
58 f2.write(i.decode())
59 f1.close()
60 f2.flush()
61 f2.close()
62 return
63
64def checkBTCbal(a):
65 r=requests.get('https://blockchain.info/q/addressbalance/'+a)
66 if not r.status_code==200:
67 print('Error',r.status_code)
68 exit(1)
69 b=int(r.text)
70 return b
71
72def checkETHbal(a,k):
73 w3 = Web3(Web3.HTTPProvider(alchemy_url+k))
74 cksum=Web3.to_checksum_address(a)
75 bal=w3.eth.get_balance(cksum)
76 return bal
77
78def bip39(mnemonic_words,n1,n2):
79 mobj = mnemonic.Mnemonic("english")
80 seed = mobj.to_seed(mnemonic_words)
81 bip32_root_key_obj = bip32utils.BIP32Key.fromEntropy(seed)
82 bip32_child_key_obj = bip32_root_key_obj.ChildKey(
83 n1 + bip32utils.BIP32_HARDEN
84 ).ChildKey(
85 n2 + bip32utils.BIP32_HARDEN
86 ).ChildKey(
87 0 + bip32utils.BIP32_HARDEN
88 ).ChildKey(0).ChildKey(0)
89 return bip32_child_key_obj.WalletImportFormat()
90
91def b58dec(s):
92 return base58.b58decode_check(s).hex()
93
94def b58enc(h):
95 return base58.b58encode_check(bytes.fromhex(h)).decode()
96
97def hex_to_bytes(hex):
98 return bytes.fromhex(hex)
99
100def bytes_to_hex(b):
101 return b.hex()
102
103def bytes_to_hex2(b):
104 return hex(b)
105
106def count_lines(file):
107 return sum(1 for line in open(file, 'r'))
108
109def hex_to_int(hex):
110 return int(hex, 16)
111
112def int_to_hex(i):
113 return hex(int(i))
114
115def int_to_bytes3(value, length = None):
116 if not length and value == 0:
117 result = [0]
118 else:
119 result = []
120 for i in range(0, length or 1+int(math.log(value, 2**8))):
121 result.append(value >> (i * 8) & 0xff)
122 result.reverse()
123 return bytearray(result)
124
125def pubkey_to_addrs(pk):
126 hdwallet = HDWallet(cryptocurrency=BTC, hd=BIP32HD)
127 hdwallet.from_public_key(public_key=pk)
128 print()
129 print(f'P2PKH: {hdwallet.address("P2PKH")}')
130 print(f'P2SH: {hdwallet.address("P2SH")}')
131 print(f'P2TR: {hdwallet.address("P2TR")}')
132 print(f'P2WPKH: {hdwallet.address("P2WPKH")}')
133 print(f'P2WPKH-In-P2SH: {hdwallet.address("P2WPKH-In-P2SH")}')
134 print(f'P2WSH: {hdwallet.address("P2WSH")}')
135 print(f'P2WSH-In-P2SH: {hdwallet.address("P2WSH-In-P2SH")}')
136 print()
137 return
138
139def pvk_to_wif2(key_hex):
140 return base58.b58encode_check(b'\x80' + bytes.fromhex(key_hex))
141
142def pvk_to_pubkey(h):
143 sk = ecdsa.SigningKey.from_string(h, curve=ecdsa.SECP256k1)
144 vk = sk.verifying_key
145 return (b'\04' + sk.verifying_key.to_string()).hex()
146
147def pvk_bin_to_addr(pvk):
148 signing_key = ecdsa.SigningKey.from_string(pvk, curve = ecdsa.SECP256k1)
149 verifying_key = signing_key.get_verifying_key()
150 public_key = bytes.fromhex("04") + verifying_key.to_string()
151 sha256_1 = hashlib.sha256(public_key)
152 ripemd160 = hashlib.new("ripemd160")
153 ripemd160.update(sha256_1.digest())
154 hashed_public_key = bytes.fromhex("00") + ripemd160.digest()
155 checksum_full = hashlib.sha256(hashlib.sha256(hashed_public_key).digest()).digest()
156 checksum = checksum_full[:4]
157 bin_addr = hashed_public_key + checksum
158 return base58.b58encode(bin_addr).decode()
159
160def str_to_hex(text):
161 return binascii.hexlify(text.encode()).decode()
162
163def wif_to_pvk(s):
164 return base58.b58decode_check(s)[0:].hex()[2:]
165
166def sha256binary(a,b):
167 i=open(a,'rb')
168 d=i.read()
169 h=hashlib.sha256(d).digest()
170 o=open(b,'wb')
171 o.write(h)
172 i.close()
173 o.flush()
174 o.close()
175 return
176
177def ripemd160binary(a,b):
178 i=open(a,'rb')
179 d=i.read()
180 h=hashlib.new('ripemd160',d).digest()
181 o=open(b,'wb')
182 o.write(h)
183 i.close()
184 o.flush()
185 o.close()
186 return
187
188def sha256hex(h):
189 return hashlib.sha256(hex_to_bytes(h)).hexdigest()
190
191def ripemd160hex(h):
192 t=hashlib.new('ripemd160',hex_to_bytes(h)).hexdigest()
193 return t
194
195def hex_to_string(h):
196 return bytes.fromhex(h).decode('utf-8')
197
198clear()
199while True:
200 print('Tool for cc v0.56 (C) 2023-2025 Aftermath @Tzeeck')
201 print('Mostly all options are for BTC if not mentioned differently')
202 print('1. seed phrase = mnemonic to HDWallet')
203 print('5. seed hex to HDWallet')
204 print('2. mnemonic to WIF - BCH Bitcoin Cash')
205 print('3. mnemonic to WIF - BTC Bitcoin')
206 print('4. mnemonic to WIF - LTC Litecoin')
207 print('6. private key integer to WIF')
208 print('7. private key integer to HDWallet')
209 print('8. private key hex to WIF')
210 print('9. private key hex to public key')
211 print('a. private key hex to HDWallet')
212 print('b. brainwallet to WIF - single')
213 print('c. brainwallet to WIF - many (a file)')
214 print('d. public key to address')
215 print('h. public key hex to hash160')
216 print('g. address to string')
217 print('i. address to public key')
218 print('s. hex to string')
219 print('r. string to hex')
220 print('f. string to address')
221 print('t. hex to int')
222 print('u. int to hex')
223 print('n. decode Base58Check to hex')
224 print('o. encode hex to Base58Check')
225 print('j. generate set')
226 print('k. generate HD wallet')
227 print('l. check BTC balance - single')
228 print('m. check ETH balance - single')
229 print('e. WIF to private key hex')
230 print('p. bytes (file) to hex')
231 print('q. convert hex to bytes (to file)')
232 print('v. count lines in file')
233 print('w. binary SHA256 (files)')
234 print('x. hex SHA256 (a file)')
235 print('y. binary RIPEMD160 (files)')
236 print('z. hex RIPEMD160 (a file)')
237 print('A. get SHA256 of hex (hex converted to binary)')
238 print('B. get RIPEMD160 of hex (hex converted to binary)')
239 print('C. ETH mnemonic (seed phrase) to address and private key')
240 print()
241 m=input('Select option or enter empty to quit: ')
242
243 match m:
244 case 'b':
245 a=input('Enter brainwallet: ')
246 print('\nWIF: '+bw2wif1(a)+'\n')
247 case 'c':
248 a=input('Enter input filename [input.txt]: ')
249 b=input('Enter output filename [output.txt]: ')
250 if a=='':
251 a='input.txt'
252 if b=='':
253 b='output.txt'
254 bw2wifmany(a,b)
255 print('Done!\n')
256 case 'l':
257 a=input('Enter BTC address: ')
258 sat=checkBTCbal(a)
259 print('\n',a,'\t',sat,'sat\t',sat/100000,'mBTC\t',sat/100000000,'BTC\n')
260 case 'm':
261 a=input('Enter ETH address: ')
262 k=input('Enter Alchemy API key: ')
263 sat=checkETHbal(a,k)
264 print('\n',a,' = ',sat/1e18,' ETH\n')
265 case '2':
266 a=input('Enter BCH mnemonic (seed phrase, usually 12 words): ')
267 print('\nWIF: '+bip39(a,44,145)+'\n')
268 case '3':
269 a=input('Enter BTC mnemonic (seed phrase, usually 12 words): ')
270 print('\nWIF: '+bip39(a,84,0)+'\n')
271 case '4':
272 a=input('Enter LTC mnemonic (seed phrase, usually 12 words): ')
273 print('\nWIF: '+bip39(a,84,2)+'\n')
274 case 'n':
275 a=input('Enter Base58Check encoded string: ')
276 print('\n'+b58dec(a)+'\n')
277 case 'o':
278 a=input('Enter hex string: ')
279 print('\n'+b58enc(a)+'\n')
280 case 'q':
281 a=input('Enter hex string: ')
282 open('output.bin','wb').write(hex_to_bytes(a))
283 print('\nWritten to output.bin file\n')
284 case 'v':
285 a=input('Enter filename [input.txt]: ')
286 if a=='':
287 a='input.txt'
288 print('\nLines count: '+str(count_lines(a))+'\n')
289 case 't':
290 a=input('Enter hex: ')
291 print('\nInteger: '+str(hex_to_int(a))+'\n')
292 case 'u':
293 a=input('Enter int: ')
294 print('\nHex: '+int_to_hex(a)+'\n')
295 case 'd':
296 a=input('Enter public key: ')
297 pubkey_to_addrs(a)
298 case '8':
299 a=input('Enter private key in hex: ')
300 a=a.zfill(64)
301 print('\nWIF uncomp: '+pvk_to_wif2(a).decode('ascii'))
302 hdwallet = HDWallet(cryptocurrency=BTC, hd=BIP32HD)
303 hdwallet.from_private_key(private_key=a)
304 print(f'WIF comp: {hdwallet.wif()}\n')
305 case '9':
306 a=input('Enter private key in hex: ')
307 a=a.zfill(64)
308 print('\nPublic key: '+pvk_to_pubkey(hex_to_bytes(a))+'\n')
309 case 'r':
310 a=input('Enter string: ')
311 print('\nHex: '+str_to_hex(a)+'\n')
312 case 'e':
313 w=input('Enter WIF: ')
314 p=wif_to_pvk(w)
315 l=len(p)
316 if l==66:
317 p=p[:-2]
318 elif l==68:
319 p=p[:-4]
320 print('\nPrivate key: '+p+'\n')
321 case 'w':
322 a=input('Enter input filename [input.bin]: ')
323 b=input('Enter output filename [output.bin]: ')
324 if a=='':
325 a='input.bin'
326 if b=='':
327 b='output.bin'
328 sha256binary(a,b)
329 case 'x':
330 a=input('Enter input filename [input.bin]: ')
331 if a=='':
332 a='input.bin'
333 i=open(a,'rb')
334 d=i.read()
335 print('\nSHA256: '+hashlib.sha256(d).hexdigest()+'\n')
336 i.close()
337 case 'y':
338 a=input('Enter input filename [input.bin]: ')
339 b=input('Enter output filename [output.bin]: ')
340 if a=='':
341 a='input.bin'
342 if b=='':
343 b='output.bin'
344 ripemd160binary(a,b)
345 case 'z':
346 a=input('Enter input filename [input.bin]: ')
347 if a=='':
348 a='input.bin'
349 i=open(a,'rb')
350 d=i.read()
351 h=hashlib.new('ripemd160',d).hexdigest()
352 print('\nRIPEMD160: '+h+'\n')
353 i.close()
354 case 'j':
355 pvk=os.urandom(32)
356 pvkhex=pvk.hex()
357 pvkhex=pvkhex.zfill(64)
358 print('\nPrivate key: '+pvkhex)
359 wif1=pvk_to_wif2(pvkhex).decode('ascii')
360 hdwallet = HDWallet(cryptocurrency=BTC, hd=BIP32HD)
361 hdwallet.from_private_key(private_key=pvkhex)
362 wif2=hdwallet.wif()
363 print('WIF uncomp : '+wif1)
364 print('WIF comp : '+wif2)
365 print('Public key : '+pvk_to_pubkey(pvk))
366 pubkey_to_addrs(pvk_to_pubkey(pvk))
367 case 'A':
368 h=input('Enter hex: ')
369 print('\nSHA256: '+sha256hex(h))
370 print()
371 case 'B':
372 h=input('Enter hex: ')
373 print('\nRIPEMD160: '+ripemd160hex(h))
374 print()
375 case 'f':
376 h=input('Enter string (up to 20 chars): ')
377 if len(h) > 20:
378 print('Too long!')
379 else:
380 h=b'\x00'+str.encode(h)
381 while len(h)<21:
382 h=h+b'\x20'
383 print('\nAddress: '+base58.b58encode_check(h).decode('utf-8'))
384 print()
385 case 'g':
386 s=input('Enter address: ')
387 print('\nString: '+base58.b58decode_check(s).decode('utf-8'))
388 print()
389 case 'h':
390 h=input('Enter public key: ')
391 print('\nHASH160: '+ripemd160hex(sha256hex(h)))
392 print()
393 case 's':
394 a=input('Enter hex: ')
395 try:
396 print('\nString: '+hex_to_string(a)+'\n')
397 except:
398 print('\nNot UTF-8 printable bytes, can\'t convert!\n')
399 case 'p':
400 a=input('Enter input filename [input.bin]: ')
401 if a=='':
402 a='input.bin'
403 i=open(a,'rb')
404 d=i.read()
405 print('\nHex: '+d.hex())
406 print()
407 i.close()
408 case 'i':
409 a=input('Enter address: ')
410 req = ('https://blockchain.info/q/pubkeyaddr/' + a)
411 resp = requests.get(req)
412 if resp.status_code == 404: print('\nNot found\n')
413 if resp.status_code == 200: print('\nPublic key:\n'+resp.text+'\n')
414 case '6':
415 i=input('Enter integer: ')
416 h=hex(int(i))[2:]
417 h=h.zfill(64)
418 if len(h)<66:
419 h='80'+h
420 p=bytes.fromhex(h)
421 b=base58.b58encode_check(p)
422 print('\nWIF uncomp: '+pvk_to_wif2(h).decode('ascii'))
423 print((b'WIF comp: '+b+b'\n').decode('utf-8'))
424 case '7':
425 a=input('Enter integer: ')
426 b=int_to_hex(a)[2:]
427 c=b.zfill(64)
428 hdwallet = HDWallet(cryptocurrency=BTC, hd=BIP32HD)
429 hdwallet.from_private_key(private_key=c)
430 d=hdwallet.dump()
431 pp = pprint.PrettyPrinter(indent=4)
432 print('\n'+pp.pformat(d))
433 print('\nWIF uncomp: '+pvk_to_wif2(c).decode('ascii')+'\n')
434 case '5':
435 j=input('Enter seed hex: ')
436 j=j.zfill(128)
437 hdwallet = HDWallet(cryptocurrency=BTC, hd=BIP32HD)
438 hdwallet.from_seed(seed=BIP39Seed(j))
439 d=hdwallet.dump()
440 print()
441 pprint.pprint(d)
442 print()
443 case 'a':
444 j=input('Enter private key hex: ')
445 j=j.zfill(64)
446 hdwallet = HDWallet(cryptocurrency=BTC, hd=BIP32HD)
447 hdwallet.from_private_key(private_key=j)
448 d=hdwallet.dump()
449 print()
450 pprint.pprint(d)
451 print('\nWIF uncomp: '+pvk_to_wif2(j).decode('ascii')+'\n')
452 case 'k':
453 hdwallet = HDWallet(cryptocurrency=BTC, hd=BIP32HD)
454 hdwallet.from_seed(seed=BIP39Seed(seed=os.urandom(64).hex()))
455 pp = pprint.PrettyPrinter(indent=4)
456 d = hdwallet.dump()
457 print('\n'+pp.pformat(d)+'\n')
458 case '1':
459 j=input('Enter seed phrase = mnemonic: ')
460 hdwallet = HDWallet(cryptocurrency=BTC, hd=BIP32HD)
461 hdwallet.from_mnemonic(mnemonic=BIP39Mnemonic(mnemonic=j))
462 d=hdwallet.dump()
463 print()
464 pprint.pprint(d)
465 print()
466 case 'C':
467 k=input('Enter Alchemy API key: ')
468 j=input('Enter seed phrase = mnemonic: ')
469 alchemy_url = 'https://eth-mainnet.g.alchemy.com/v2/'+k
470 w3 = Web3(Web3.HTTPProvider(alchemy_url))
471 w3.eth.account.enable_unaudited_hdwallet_features()
472 try:
473 acc = w3.eth.account.from_mnemonic(j)
474 except:
475 print('Error: bad mnemonic')
476 pass
477 address = w3.to_checksum_address(acc.address)
478 h=acc._private_key.hex()
479 print()
480 print('Checksum address: '+address)
481 print('Private key: '+h)
482 print()
483 case '':
484 exit(0)
485 input('Press Enter...')
486