Bitcoin Forum
September 16, 2024, 02:13:02 AM *
News: Latest Bitcoin Core release: 27.1 [Torrent]
 
  Home Help Search Login Register More  
  Show Posts
Pages: [1]
1  Bitcoin / Development & Technical Discussion / Re: Simple private key to public key converter on: December 16, 2022, 06:37:17 AM
Hi
Any one have python code for
Public key to address converter
Public key =Input.txt file
Address = output.txt file

Input file to output file

I spent ten minutes writing this program, I hope you like it. Ask questions if there is something you don't understand.
Please do not use this script for any serious stuff!

Pub keys need to be in this format:

Code:
02F9308A019258C31049344F85F89D5229B531C845836F99B08601F113BCE036F9
02E493DBF1C10D80F3581E4904930B1404CC6C13900EE0758474FA94ABE8C4CD13
03421F5FC9A21065445C96FDB91C0C1E2F2431741C72713B4B99DDCB316F31E9FC
...
Result:
Code:
1CUNEBjYrCn2y1SdiUMohaKUi4wpP326Lb
1JtK9CQw1syfWj1WtFMWomrYdV3W2tWBF9
1GWqhXL1DGAEc6MVntAnmQe4GFnR9k2Ykd
...
Code:
import base58
import sys

# these modules are taken from here https://github.com/karpathy/cryptos/tree/main/cryptos
from ripemd160 import ripemd160
from sha256 import sha256


def public_address(key):
    key = bytes.fromhex(key)
    address = bytes.fromhex(f"00{ripemd160(sha256(key)).hex()}")
    checksum = sha256(sha256(address))
    address = f"{address.hex()}{checksum.hex()[:8]}"
    address = base58.b58encode(bytes.fromhex(address)).decode("UTF-8")
    return address


if len(sys.argv) < 3:
    print('Usage: app.py <path/to/src> <path/to/dest>')
    sys.exit(1)

path_src = sys.argv[1]
path_dest = sys.argv[2]
addresses = []

with open(path_src, 'r', encoding='UTF-8') as file:
    pub_keys = file.readlines()

pub_keys = (pub_key.strip() for pub_key in pub_keys)

for pub_key in pub_keys:
    addr = public_address(pub_key)
    addresses.append(addr)

with open(path_dest, 'w', encoding='UTF-8') as file:
    for address in addresses:
        file.write(address + '\n')

Thankyou very much
It's working perfectly ...
2  Bitcoin / Development & Technical Discussion / Re: Simple private key to public key converter on: December 15, 2022, 02:00:28 PM
Thankyou

I will check and get back to you
3  Bitcoin / Development & Technical Discussion / Re: Simple private key to public key converter on: December 15, 2022, 01:25:57 PM
Hi
Any one have python code for
Public key to address converter
Public key =Input.txt file
Address = output.txt file

Input file to output file
Pages: [1]
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!