|
| 1 | +import hashlib,base58,binascii |
| 2 | + |
| 3 | +# it is not used but it is another way to convert Byte to Hex |
| 4 | +def convertByteToHex(inp): |
| 5 | + return ''.join(["%02x" % x for x in inp]) |
| 6 | + |
| 7 | +# mypublickey = '1M2tgkBsUeo2XYAjgapENNb2kxH1gzY3VH' |
| 8 | + |
| 9 | +bitcoinAddress = input("Enter a bitcoin address:") |
| 10 | +print("--------------------------------------") |
| 11 | +print("Bitcoin Address: ", bitcoinAddress) |
| 12 | +# base58.b58decode method generate Byte and we should convert it to Hex with hex() method |
| 13 | +base58Decoder = base58.b58decode(bitcoinAddress).hex() |
| 14 | +print("Base58 Decoder: ", base58Decoder) |
| 15 | +prefixAndHash = base58Decoder[:len(base58Decoder)-8] |
| 16 | +checksum = base58Decoder[len(base58Decoder)-8:] |
| 17 | +print("\t|___> Prefix & Hash: ", prefixAndHash) |
| 18 | +print("\t|___> Checksum: ", checksum) |
| 19 | +print("--------------------------------------") |
| 20 | +# to handle true result, we should pass our input to hashlib.sha256() method() as Byte format |
| 21 | +# so we use binascii.unhexlify() method to convert our input from Hex to Byte |
| 22 | +# finally, hexdigest() method convert value to human-readable |
| 23 | +hash = prefixAndHash |
| 24 | +for x in range(1,3): |
| 25 | + hash = hashlib.sha256(binascii.unhexlify(hash)).hexdigest() |
| 26 | + print("Hash#", x, " : ", hash) |
| 27 | +print("--------------------------------------") |
| 28 | +if(checksum == hash[:8]): |
| 29 | + print("[TRUE] checksum is valid!") |
| 30 | +else: |
| 31 | + print("[FALSE] checksum is not valid!") |
0 commit comments