Bitcoin Forum
May 24, 2024, 12:42:41 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: « 1 [2]  All
  Print  
Author Topic: Simple private key to public key converter  (Read 615 times)
ramakrishna0905
Newbie
*
Offline Offline

Activity: 3
Merit: 0


View Profile
December 16, 2022, 06:37:17 AM
 #21

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 ...
witcher_sense
Legendary
*
Offline Offline

Activity: 2352
Merit: 4369


🔐BitcoinMessage.Tools🔑


View Profile WWW
December 16, 2022, 07:39:11 AM
 #22

Thankyou very much
It's working perfectly ...
I am glad to hear that, here is optimized version of the script, it should run a little bit faster: https://github.com/witcher-sense/learning_python/blob/main/public_to_address.py

█▀▀▀











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











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
n0nce
Hero Member
*****
Offline Offline

Activity: 882
Merit: 5829


not your keys, not your coins!


View Profile WWW
December 17, 2022, 12:22:08 AM
Merited by witcher_sense (2)
 #23

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'm just commenting to say that I find such questions kind of disrespectful. You're just asking people to write code for you for free; you didn't put in any effort trying to do it yourself.
I can say this confidently, because even an inexperienced programmer can figure out how to read and write to files in Python within 10 minutes, try it out, then take some more minutes to incorporate it into one of the scripts that people have already written in this thread for free.

Also @release: after getting provided a script doing exactly what you wanted, you still weren't happy or thankful for it and asked to get it in a different programming language.

I recommend to follow the How to ask a good question standards from StackOverflow.
You're honestly lucky that people have written so much code with comments and everything else in this thread, after you guys literally showed 0 effort yourself, attempting to build whatever you need (or even just parts of it!).

█▀▀▀











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











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
bkelly13
Member
**
Offline Offline

Activity: 63
Merit: 33


View Profile
December 21, 2022, 02:49:52 AM
 #24

Keep in mind that most people don't write their own because there are already libraries in most languages that have been tested.

Sure, but I have to say that I found it quite fun to write my own C program that would take a file of private keys and generate the associated public keys and Legacy bitcoin addresses.

I would really like to see that.  If too much to post here I will PM an email address.

BTW:  As I was going through this thread a few minutes ago there was a post where someone provided a list of about eight links to various descriptions of the process of private to public key.  I have some hand tremors and while looking through the list I clicked something and went to a totally different page.  Now when I scroll through the posts of this thread I cannot find that post again.  Is there something I might have done that will hide a post?  Something that will unhide the post?
Pages: « 1 [2]  All
  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!