Bitcoin Forum
November 05, 2024, 11:34:16 PM *
News: Latest Bitcoin Core release: 28.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Converting RIPEMD160 to address  (Read 193 times)
Stroncow (OP)
Jr. Member
*
Offline Offline

Activity: 38
Merit: 13


View Profile
April 06, 2021, 11:28:50 AM
 #1

I want to convert all hash160s in the list to addresses.

This code did not work for me, what should I do to edit it?

Code:
from bitcoin import *

hash160 = '010966776006953D5567439E5E39F86A0D273BEE'
addr = pubtoaddr(hash160)
print (addr)
BlackHatCoiner
Legendary
*
Offline Offline

Activity: 1694
Merit: 8324


Bitcoin is a royal fork


View Profile WWW
April 06, 2021, 11:46:41 AM
 #2

I haven't work with python in the past, but based on the code you posted, you're performing a function falsely. Precisely, it's pubtoaddr(string). As far as I can read from the code, you should enter a public key as a string parameter of that function, not a hash160.

I'm saying this without knowing what that function do, I just understand it from its name. A python expert could give you a better answer.

█▀▀▀











█▄▄▄
▀▀▀▀▀▀▀▀▀▀▀
e
▄▄▄▄▄▄▄▄▄▄▄
█████████████
████████████▄███
██▐███████▄█████▀
█████████▄████▀
███▐████▄███▀
████▐██████▀
█████▀█████
███████████▄
████████████▄
██▄█████▀█████▄
▄█████████▀█████▀
███████████▀██▀
████▀█████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
c.h.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀█











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
NotATether
Legendary
*
Offline Offline

Activity: 1778
Merit: 7362


Top Crypto Casino


View Profile WWW
April 06, 2021, 12:07:05 PM
Merited by ABCbits (1), hugeblack (1), nc50lc (1)
 #3

Install the base58 library from Pip and use the base58.base58encode_check(bytestring) function to encode it.

Code:
import base58

hash160 = '010966776006953D5567439E5E39F86A0D273BEE'

# convert your hex string into a byte array like this:
b = bytes.fromhex(hash160)

addr = base58.b58encode_check(b).decode('utf-8')  # Should give you the address
print(addr)

███████████████████████
████▐██▄█████████████████
████▐██████▄▄▄███████████
████▐████▄█████▄▄████████
████▐█████▀▀▀▀▀███▄██████
████▐███▀████████████████
████▐█████████▄█████▌████
████▐██▌█████▀██████▌████
████▐██████████▀████▌████
█████▀███▄█████▄███▀█████
███████▀█████████▀███████
██████████▀███▀██████████

███████████████████████
.
BC.GAME
▄▄▀▀▀▀▀▀▀▄▄
▄▀▀░▄██▀░▀██▄░▀▀▄
▄▀░▐▀▄░▀░░▀░░▀░▄▀▌░▀▄
▄▀▄█▐░▀▄▀▀▀▀▀▄▀░▌█▄▀▄
▄▀░▀░░█░▄███████▄░█░░▀░▀▄
█░█░▀░█████████████░▀░█░█
█░██░▀█▀▀█▄▄█▀▀█▀░██░█
█░█▀██░█▀▀██▀▀█░██▀█░█
▀▄▀██░░░▀▀▄▌▐▄▀▀░░░██▀▄▀
▀▄▀██░░▄░▀▄█▄▀░▄░░██▀▄▀
▀▄░▀█░▄▄▄░▀░▄▄▄░█▀░▄▀
▀▄▄▀▀███▄███▀▀▄▄▀
██████▄▄▄▄▄▄▄██████
.
..CASINO....SPORTS....RACING..


▄▄████▄▄
▄███▀▀███▄
██████████
▀███▄░▄██▀
▄▄████▄▄░▀█▀▄██▀▄▄████▄▄
▄███▀▀▀████▄▄██▀▄███▀▀███▄
███████▄▄▀▀████▄▄▀▀███████
▀███▄▄███▀░░░▀▀████▄▄▄███▀
▀▀████▀▀████████▀▀████▀▀
Stroncow (OP)
Jr. Member
*
Offline Offline

Activity: 38
Merit: 13


View Profile
April 06, 2021, 03:17:11 PM
Merited by LoyceV (2), hugeblack (1), NotATether (1)
 #4

Install the base58 library from Pip and use the base58.base58encode_check(bytestring) function to encode it.

Code:
import base58

hash160 = '010966776006953D5567439E5E39F86A0D273BEE'

# convert your hex string into a byte array like this:
b = bytes.fromhex(hash160)

addr = base58.b58encode_check(b).decode('utf-8')  # Should give you the address
print(addr)

Thank you. I added them.

Code:
import base58

with open('2.txt', 'r') as f:
for hash160 in f:
key_hash = '00' + hash160
b = bytes.fromhex(key_hash)
addr = base58.b58encode_check(b).decode('utf-8')
open('addresses.txt', 'a').write(addr + '\n')
fxsniper
Member
**
Offline Offline

Activity: 406
Merit: 47


View Profile
April 06, 2021, 05:41:06 PM
 #5


if want to reverse address to RIPEMD160 for recheck is correct (or use convert address to RIPEMD160)

Do you have simple code?
NotATether
Legendary
*
Offline Offline

Activity: 1778
Merit: 7362


Top Crypto Casino


View Profile WWW
April 07, 2021, 05:38:39 AM
 #6


if want to reverse address to RIPEMD160 for recheck is correct (or use convert address to RIPEMD160)

Do you have simple code?

The base58 library provides a base58decode_check function that decodes a byte-encoded base58 string back into a byte array. Note that you must convert the base58 string to bytes first before you can pass it as an argument, and because you not only get RIPEMD160 bytes but also the checksum back, you need to strip the checksum too.

Code:
import base58

addr = "insert base58 address here"

bytesaddr = bytes(addr, "utf-8")
r160check = base58.base58decode_check(bytesaddr).decode('utf-8');

r160 = r160check[2:] # If you put a "00" at the beginning of the string, so remove it
print(r160)

███████████████████████
████▐██▄█████████████████
████▐██████▄▄▄███████████
████▐████▄█████▄▄████████
████▐█████▀▀▀▀▀███▄██████
████▐███▀████████████████
████▐█████████▄█████▌████
████▐██▌█████▀██████▌████
████▐██████████▀████▌████
█████▀███▄█████▄███▀█████
███████▀█████████▀███████
██████████▀███▀██████████

███████████████████████
.
BC.GAME
▄▄▀▀▀▀▀▀▀▄▄
▄▀▀░▄██▀░▀██▄░▀▀▄
▄▀░▐▀▄░▀░░▀░░▀░▄▀▌░▀▄
▄▀▄█▐░▀▄▀▀▀▀▀▄▀░▌█▄▀▄
▄▀░▀░░█░▄███████▄░█░░▀░▀▄
█░█░▀░█████████████░▀░█░█
█░██░▀█▀▀█▄▄█▀▀█▀░██░█
█░█▀██░█▀▀██▀▀█░██▀█░█
▀▄▀██░░░▀▀▄▌▐▄▀▀░░░██▀▄▀
▀▄▀██░░▄░▀▄█▄▀░▄░░██▀▄▀
▀▄░▀█░▄▄▄░▀░▄▄▄░█▀░▄▀
▀▄▄▀▀███▄███▀▀▄▄▀
██████▄▄▄▄▄▄▄██████
.
..CASINO....SPORTS....RACING..


▄▄████▄▄
▄███▀▀███▄
██████████
▀███▄░▄██▀
▄▄████▄▄░▀█▀▄██▀▄▄████▄▄
▄███▀▀▀████▄▄██▀▄███▀▀███▄
███████▄▄▀▀████▄▄▀▀███████
▀███▄▄███▀░░░▀▀████▄▄▄███▀
▀▀████▀▀████████▀▀████▀▀
fxsniper
Member
**
Offline Offline

Activity: 406
Merit: 47


View Profile
April 08, 2021, 02:23:11 PM
 #7


if want to reverse address to RIPEMD160 for recheck is correct (or use convert address to RIPEMD160)

Do you have simple code?

The base58 library provides a base58decode_check function that decodes a byte-encoded base58 string back into a byte array. Note that you must convert the base58 string to bytes first before you can pass it as an argument, and because you not only get RIPEMD160 bytes but also the checksum back, you need to strip the checksum too.

Code:
import base58

addr = "insert base58 address here"

bytesaddr = bytes(addr, "utf-8")
r160check = base58.base58decode_check(bytesaddr).decode('utf-8');

r160 = r160check[2:] # If you put a "00" at the beginning of the string, so remove it
print(r160)

Thank you NotATether
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!