How to convert a Bitcoin private key to a public key to speed up the process, we will use the Bloom filter algorithm

20.03.2025
How to convert a Bitcoin private key to a public key to speed up the process, we will use the Bloom filter algorithm

Converting a Bitcoin private key to a public key can be done using a library ecdsain hashlibPython. However, using the Bloom filter algorithm to speed up the process does not make direct sense in this context, since the Bloom filter is used to quickly determine whether an element is in a set, not to perform cryptographic transformations.

Below is an example script that converts a Bitcoin private key to a public key in uncompressed and compressed form:

pythonimport ecdsa
import hashlib

def private_to_public(private_key_hex):
    # Создаем объект закрытого ключа
    sk = ecdsa.SigningKey.from_string(bytes.fromhex(private_key_hex), curve=ecdsa.SECP256k1)
    
    # Получаем объект открытого ключа
    vk = sk.get_verifying_key()
    
    # Несжатый открытый ключ
    public_key_uncompressed = vk.to_string().hex()
    
    # Сжатый открытый ключ
    public_key_compressed = vk.to_string().hex()[:2] + '0' + vk.to_string().hex()[2:64] if int(vk.to_string().hex()[64:], 16) % 2 == 0 else vk.to_string().hex()[:2] + '1' + vk.to_string().hex()[2:64]
    
    return public_key_uncompressed, public_key_compressed

def private_wif_to_hex(private_key_wif):
    # Для конвертации WIF в HEX можно использовать сторонние библиотеки или реализовать самому
    # Для простоты будем считать, что конвертация уже сделана
    return private_key_wif  # Это нужно заменить на реальную конвертацию

def main():
    private_key_hex = "aa35fda8f16d06ae02bdcf671e03035795a0b0ecbdae45098928f6587016a932"
    # или
    private_key_wif = "L2vaWmjh7XpV9AMWDjmNSGPQNEd4QG7YGAMMqPEmGSt8WSppysCV"
    
    if private_key_wif:
        private_key_hex = private_wif_to_hex(private_key_wif)
    
    public_key_uncompressed, public_key_compressed = private_to_public(private_key_hex)
    
    print(f"Несжатый открытый ключ: {public_key_uncompressed}")
    print(f"Сжатый открытый ключ: {public_key_compressed}")

if __name__ == "__main__":
    main()

This script uses a library ecdsato work with keys. To convert WIF to HEX, you may need an additional library or implement your own conversion function.

Note : This example uses a simplification to convert WIF to HEX. In a real application, you would either need to use a library that supports this format or implement the conversion manually.

Installing the required libraries :

bashpip install ecdsa

Using Bloom filter in this context does not make sense, since it is used to quickly determine whether an element is in a set, not for cryptographic transformations.

What are the ready-made scripts for converting Bitcoin keys?

There are several ready-made scripts and libraries for converting Bitcoin keys. Here are some of them:

  1. Python scripts from CryptoDeepTools :
    • pubtoaddr.py : This script converts Bitcoin public keys (HEX) to Bitcoin addresses (Base58). It is used in combination with other scripts to check the balance of addresses 1 .
    • bitcoin-checker.py : Used to check the balance of Bitcoin addresses derived from public keys 1 .
  2. libbtc library :
    • This library can help with working with Bitcoin keys, including converting private keys to public keys. It is available for C++ and can be useful for developing your own applications 5 .
  3. Python libraries :
    • ecdsa : Used to work with elliptic curves and can be used to convert private keys to public keys 5 .
    • base58 : Used to encode and decode Bitcoin addresses in Base58 format 1 .

These tools can be useful for various tasks related to converting and verifying Bitcoin keys.

Example of using Python libraries :

pythonimport ecdsa
import hashlib
import base58

def private_to_public(private_key_hex):
    sk = ecdsa.SigningKey.from_string(bytes.fromhex(private_key_hex), curve=ecdsa.SECP256k1)
    vk = sk.get_verifying_key()
    return vk.to_string().hex()

def public_to_address(public_key_hex):
    # Применение хеш-функций и кодировка Base58
    public_key_bytes = bytes.fromhex(public_key_hex)
    sha256_hash = hashlib.sha256(public_key_bytes).digest()
    ripemd160_hash = hashlib.new('ripemd160', sha256_hash).digest()
    
    # Добавление префикса и контрольной суммы для Base58
    address_bytes = b'\x00' + ripemd160_hash
    checksum = hashlib.sha256(hashlib.sha256(address_bytes).digest()).digest()[:4]
    address_bytes += checksum
    
    return base58.b58encode(address_bytes).decode('utf-8')

# Пример использования
private_key_hex = "aa35fda8f16d06ae02bdcf671e03035795a0b0ecbdae45098928f6587016a932"
public_key_hex = private_to_public(private_key_hex)
bitcoin_address = public_to_address(public_key_hex)

print(f"Bitcoin Address: {bitcoin_address}")

This example shows how to convert a private key to a public key and then to a Bitcoin address.

What scripts are there to convert Bitcoin keys to other formats

There are several scripts and libraries for converting Bitcoin keys into different formats. Here are some examples:

  1. Python libraries :
    • ecdsa : Used to work with elliptic curves and can be used to convert private keys to public keys.
    • base58 : Used to encode and decode Bitcoin addresses in Base58 format.
    • pycryptodome : Can be used for cryptographic operations, including key conversion.
  2. Scripts for converting keys :
    • pubtoaddr.py : Script that converts Bitcoin public keys (HEX) to Bitcoin addresses (Base58).
    • bitcoin-checker.py : Used to check the balance of Bitcoin addresses derived from public keys.
  3. Open source tools :
    • Swippcore : Used to convert short format keys to long format keys on the local machine 7 .
  4. Online tools :
    • There are various online services that allow you to convert Bitcoin keys, but using them is not recommended due to security risks.

Example Python script for converting keys :

pythonimport ecdsa
import hashlib
import base58

def private_to_public(private_key_hex):
    sk = ecdsa.SigningKey.from_string(bytes.fromhex(private_key_hex), curve=ecdsa.SECP256k1)
    vk = sk.get_verifying_key()
    return vk.to_string().hex()

def public_to_address(public_key_hex):
    public_key_bytes = bytes.fromhex(public_key_hex)
    sha256_hash = hashlib.sha256(public_key_bytes).digest()
    ripemd160_hash = hashlib.new('ripemd160', sha256_hash).digest()
    address_bytes = b'\x00' + ripemd160_hash
    checksum = hashlib.sha256(hashlib.sha256(address_bytes).digest()).digest()[:4]
    address_bytes += checksum
    return base58.b58encode(address_bytes).decode('utf-8')

# Пример использования
private_key_hex = "aa35fda8f16d06ae02bdcf671e03035795a0b0ecbdae45098928f6587016a932"
public_key_hex = private_to_public(private_key_hex)
bitcoin_address = public_to_address(public_key_hex)

print(f"Bitcoin Address: {bitcoin_address}")

This script converts a private key to a public key and then to a Bitcoin address.

Installing the required libraries :

bashpip install ecdsa base58

Note : Converting WIF to HEX or other formats may require additional logic or the use of third-party libraries.

What are the tools for managing Bitcoin keys?

There are several tools and libraries for managing Bitcoin keys, including conversion and secure storage. Here are some of them:

  1. Python libraries :
    • ecdsa : Used to work with elliptic curves and can be used to convert private keys to public keys.
    • base58 : Used to encode and decode Bitcoin addresses in Base58 format.
  2. Wallets with key management features :
    • Bitcoin.com Wallet : Provides full control over private keys and supports multiple cryptocurrencies.
    • Byte Federal : Supports a wide range of digital assets and provides secure storage and transactions.
    • MetaMask : A popular wallet for Ethereum, but can also be used for other cryptocurrencies with support for multiple networks.
  3. Hardware wallets :
    • Ledger , Trezor : Well-known hardware wallets that provide secure storage of private keys and support multiple cryptocurrencies.
  4. Key conversion tools :
    • pubtoaddr.py : Script for converting public keys to Bitcoin addresses.
    • bitcoin-checker.py : Used to check the balance of Bitcoin addresses.
  5. Online tools :
    • There are various online services for converting and managing keys, but their use is not recommended due to security risks.

Example Python script for converting keys :

pythonimport ecdsa
import hashlib
import base58

def private_to_public(private_key_hex):
    sk = ecdsa.SigningKey.from_string(bytes.fromhex(private_key_hex), curve=ecdsa.SECP256k1)
    vk = sk.get_verifying_key()
    return vk.to_string().hex()

def public_to_address(public_key_hex):
    public_key_bytes = bytes.fromhex(public_key_hex)
    sha256_hash = hashlib.sha256(public_key_bytes).digest()
    ripemd160_hash = hashlib.new('ripemd160', sha256_hash).digest()
    address_bytes = b'\x00' + ripemd160_hash
    checksum = hashlib.sha256(hashlib.sha256(address_bytes).digest()).digest()[:4]
    address_bytes += checksum
    return base58.b58encode(address_bytes).decode('utf-8')

# Пример использования
private_key_hex = "aa35fda8f16d06ae02bdcf671e03035795a0b0ecbdae45098928f6587016a932"
public_key_hex = private_to_public(private_key_hex)
bitcoin_address = public_to_address(public_key_hex)

print(f"Bitcoin Address: {bitcoin_address}")

This script converts a private key to a public key and then to a Bitcoin address.

Installing the required libraries :

bashpip install ecdsa base58

Note : Converting WIF to HEX or other formats may require additional logic or the use of third-party libraries.

Citations:

  1. https://www.bitcoin.com/ru/bitcoin-wallet-directory/
  2. https://www.cryptopro.ru/blog/2019/05/21/instrumenty-cryptopro-krossplatformennyi-graficheskii-interfeis
  3. https://intuit.ru/studies/courses/3520/762/lecture/32518
  4. https://www.binance.com/ru/blog/ecosystem/%D0%BF%D1%83%D0%B1%D0%BB%D0%B8%D1%87%D0%BD%D1%8B%D 0%B5-%D0%BA%D0%BB%D1%8E%D1%87%D0%B8-%D0%B8-%D0%BF%D1%80%D0%B8%D0%B2%D0%B0%D1%82%D0%BD%D1%8B%D 0%B5-%D0%BA%D0%BB%D1%8E%D1%87%D0%B8-%D1%87%D1%82%D0%BE-%D1%8D%D1%82%D0%BE-%D0%B8-%D0%BA%D0%B0 %D0%BA-%D0%BE%D0%BD%D0%B8-%D1%80%D0%B0%D0%B1%D0%BE%D1%82%D0%B0%D1%8E%D1%82-421499824684903332
  5. https://ru.wikipedia.org/wiki/%D0%A3%D0%BF%D1%80%D0%B0%D0%B2%D0%BB%D0%B5%D0%BD%D0%B8%D0%B5_%D0%BA%D0%BB%D1%8E%D1%87%D0%B0%D0%BC%D0%B8
  6. https://intelionmine.ru/blog/kosel_ki_dla_bitkoina_kak_i_gde_hranit_pervuu_kriptovalutu
  7. https://habr.com/ru/companies/aktiv-company/articles/341456/
  8. https://cryptocloud.plus/blog/kriptovalyutnyj-shlyuz-dlya-bitkoina

  1. https://decimalchain.com/blog/ru/bitcoin-script-osnovy-dlya-nachinayushhix/
  2. https://www.binance.com/ru/blog/ecosystem/%D0%BF%D1%83%D0%B1%D0%BB%D0%B8%D1%87%D0%BD%D1%8B%D 0%B5-%D0%BA%D0%BB%D1%8E%D1%87%D0%B8-%D0%B8-%D0%BF%D1%80%D0%B8%D0%B2%D0%B0%D1%82%D0%BD%D1%8B%D 0%B5-%D0%BA%D0%BB%D1%8E%D1%87%D0%B8-%D1%87%D1%82%D0%BE-%D1%8D%D1%82%D0%BE-%D0%B8-%D0%BA%D0%B0 %D0%BA-%D0%BE%D0%BD%D0%B8-%D1%80%D0%B0%D0%B1%D0%BE%D1%82%D0%B0%D1%8E%D1%82-421499824684903332
  3. https://habr.com/ru/articles/674812/
  4. https://academy.binance.com/ru/articles/an-introduction-to-bitcoin-script
  5. https://forklog.com/cryptorium/kakie-formaty-byvayut-u-bitkoin-adresov
  6. https://habr.com/ru/companies/distributedlab/articles/413627/
  7. https://ru.tradingview.com/news/forklog:3031939c867b8:0/
  8. https://ibmm.ru/news/kriptoindustriya/bitkoin-adres/

  1. https://cryptodeep.ru/check-bitcoin-address-balance/
  2. https://habr.com/ru/articles/674812/
  3. https://decimalchain.com/blog/ru/bitcoin-script-osnovy-dlya-nachinayushhix/
  4. https://intuit.ru/studies/courses/3520/762/lecture/32518
  5. https://ru.stackoverflow.com/questions/770568/%D0%9F%D0%BE%D0%BB%D1%83%D1%87%D0%B8%D1%82%D1%8C-%D0%BF%D1%83%D0%B1%D0%BB%D0%B8%D1 %87%D0%BD%D1%8B%D0%B9-%D0%BA%D0%BB%D1%8E%D1%87-%D0%B8%D0%B7-%D0% BF%D1%80%D0%B8%D0%B2%D0%B0%D1%82%D0%BD%D0%BE%D0%B3%D0%BE-bitcoin
  6. https://habr.com/ru/companies/distributedlab/articles/413627/
  7. https://finance.rambler.ru/money/54008586-samym-prostym-sposobom-dlya-konvertatsii-rubley-na-kriptu-okazalis-punkty-obmena/
  8. https://www.kaspersky.ru/blog/fake-macos-activator-steals-bitcoin-exodus-uses-dns/36901/

  1. https://ru.stackoverflow.com/questions/1475317/bitcoin-%D0%B0%D0%B4%D1%80%D0%B5%D1%81%D0%B0-%D1%84%D0%BE%D1%80%D0%BC%D0%B0%D1%82
  2. https://generate.mitilena.com/ru/offline/private-btc-to-wif/
  3. https://forum.bits.media/index.php?%2Fblogs%2Fentry%2F3154-%D1%81%D0%B0%D0%BC%D0%B0%D1%8F-%D0%BF%D0%B5%D1%80%D0%B2%D0%B0%D1%8F-%D1%81 %D0%B5%D1%80%D1%8C%D0%B5%D0%B7%D0%BD%D0%B0%D1%8F-%D1%83%D1%8F%D0%B7 %D0%B2%D0%B8%D0%BC%D0%BE%D1%81%D1%82%D1%8C-%D0%B2-blockchain-%D0%B8 -%D0%BA%D0%B0%D0%BA-%D0%BF%D0%BE%D0%BB%D1%83%D1%87%D0%B8%D1%82%D1%8 C-%D0%BF%D1%83%D0%B1%D0%BB%D0%B8%D1%87%D0%BD%D1%8B%D0%B9-%D0%BA%D0% BB%D1%8E%D1%87-bitcoin-ecdsa-%D0%B7%D0%BD%D0%B0%D1%87%D0%B5%D0%BD%D 0%B8%D0%B5-rsz-%D0%B8%D0%B7-%D1%84%D0%B0%D0%B9%D0%BB%D0%B0-rawtx%2F
  4. https://ru.stackoverflow.com/questions/681298/%D0%9A%D0%B0%D0%BA-%D0%B7%D0%B0%D1%88%D0 %B8%D1%84%D1%80%D0%BE%D0%B2%D0%B0%D1%82%D1%8C-%D0%B7%D0%B0%D0%BA%D1%80%D1%8B%D1%82%D1%8 B%D0%BC-%D0%BA%D0%BB%D1%8E%D1%87%D0%BE%D0%BC-%D0%B8-%D1%80%D0%B0%D1%81%D1%88%D0%B8%D1% 84%D1%80%D0%BE%D0%B2%D0%B0%D1%82%D1%8C-%D0%BE%D1%82%D0%BA%D1%80%D1%8B%D1%82%D1%8B%D0%BC
  5. https://bitnovosti.io/2025/01/18/python-bitcoin-crypto/
  6. https://habr.com/ru/articles/564256/
  7. https://cryptodeep.ru/rowhammer-attack/
  8. https://proglib.io/p/new-bitcoin

Source code

Telegram: https://t.me/cryptodeeptech

Video: https://youtu.be/i9KYih_ffr8

Video tutorial: https://dzen.ru/video/watch/6784be61b09e46422395c236

Source: https://cryptodeeptech.ru/discrete-logarithm


Useful information for enthusiasts:


Discrete Logarithm mathematical methods and tools for recovering cryptocurrency wallets Bitcoin