Python Tool of Base58 Decode Check

in #programming3 years ago

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:

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.

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:

$ 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}

Reposted to Blog

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Thank you for reading ^^^^^^^^^^^^^^^

NEW! Following my Trail (Upvote or/and Downvote)

Follow me for topics of Algorithms, Blockchain and Cloud.
I am @justyy - a Steem Witness
https://steemyy.com

My contributions

Delegation Service

  1. Voting Algorithm Updated to Favor those High Delegations!
  • Delegate 1000 to justyy: Link
  • Delegate 5000 to justyy: Link
  • Delegate 10000 to justyy: Link

Support me

If you like my work, please:

  1. Delegate SP: https://steemyy.com/sp-delegate-form/?delegatee=justyy
  2. Vote @justyy as Witness: https://steemyy.com/witness-voting/?witness=justyy&action=approve
  3. Set @justyy as Proxy: https://steemyy.com/witness-voting/?witness=justyy&action=proxy
    Alternatively, you can vote witness or set proxy here: https://steemit.com/~witnesses

Sort:  

Hola siguiendote.

hi @justyy,..i delegate steem to you, but you give a very small upvote for me. this really makes me want to confirm it with you. I wish you always success and this platform is more advanced and growing.. greetings by @abughaisan84

Coin Marketplace

STEEM 0.21
TRX 0.20
JST 0.034
BTC 98129.50
ETH 3322.67
USDT 1.00
SBD 3.05