Python Tool of Base58 Decode Check


tron-blockchain Python Tool of Base58 Decode Check blockchain Cryptocurrency Cryptocurrency cryptography python Tron Tron Blockchain

tron-blockchain

Base58 originates from bitcoin where the inventor Satoshi intentionally removes “iILloO0” which are confusing letters/digits when they appear in printing..

Base58 uses the following character set:

1
123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz
123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz

In Blockchain such as bitcoins or Tron, the public wallet address is computed from private keys (256 bit random bytes). The wallet address is a base58 string, and we can decode and check the checksum. The following is a Python command line tool that uses the base58 library to perform the b58decode_check for the addresses.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import base58
import sys
 
def address_hex(address):
    arr = base58.b58decode_check(address).hex().lower()
    s = []
    for i in range(0, len(arr) - 1, 2):
        s.append("0x" + arr[i] + arr[i + 1])
    return "{" + ",".join(s) + "}"
 
if len(sys.argv) <= 1:
    print("Usage: " + sys.argv[0] + " str1 str2 ...")
    exit()
 
for i in sys.argv[1:]:
    print(i)
    print(address_hex(i))
import base58
import sys

def address_hex(address):
    arr = base58.b58decode_check(address).hex().lower()
    s = []
    for i in range(0, len(arr) - 1, 2):
        s.append("0x" + arr[i] + arr[i + 1])
    return "{" + ",".join(s) + "}"

if len(sys.argv) <= 1:
    print("Usage: " + sys.argv[0] + " str1 str2 ...")
    exit()

for i in sys.argv[1:]:
    print(i)
    print(address_hex(i))

For example:

1
2
3
4
5
$ python3 b58.py TFczxzPhnThNSqr5by8tvxsdCFRRz6cPNq TSSMHYeV2uE9qYH95DqyoCuNCzEL1NvU3S
TFczxzPhnThNSqr5by8tvxsdCFRRz6cPNq
{0x41,0x3d,0xfe,0x63,0x7b,0x2b,0x9a,0xe4,0x19,0x0a,0x45,0x8b,0x5f,0x3e,0xfc,0x19,0x69,0xaf,0xe2,0x78,0x19}
TSSMHYeV2uE9qYH95DqyoCuNCzEL1NvU3S
{0x41,0xb4,0xa4,0x28,0xab,0x70,0x92,0xc2,0xf1,0x39,0x5f,0x37,0x6c,0xe2,0x97,0x03,0x3b,0x3b,0xb4,0x46,0xc1}
$ python3 b58.py TFczxzPhnThNSqr5by8tvxsdCFRRz6cPNq TSSMHYeV2uE9qYH95DqyoCuNCzEL1NvU3S
TFczxzPhnThNSqr5by8tvxsdCFRRz6cPNq
{0x41,0x3d,0xfe,0x63,0x7b,0x2b,0x9a,0xe4,0x19,0x0a,0x45,0x8b,0x5f,0x3e,0xfc,0x19,0x69,0xaf,0xe2,0x78,0x19}
TSSMHYeV2uE9qYH95DqyoCuNCzEL1NvU3S
{0x41,0xb4,0xa4,0x28,0xab,0x70,0x92,0xc2,0xf1,0x39,0x5f,0x37,0x6c,0xe2,0x97,0x03,0x3b,0x3b,0xb4,0x46,0xc1}

Tron Blockchain

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
625 words
Last Post: Teaching Kids Programming - Rotate a 2D Matrix/Image 90 Degree Clockwise
Next Post: GoLang: Check If N and Its Double Exist (Hash Map)

The Permanent URL is: Python Tool of Base58 Decode Check

Leave a Reply