Advertisement
skip420

BTC_Finder

Jun 2nd, 2019
2,173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.69 KB | None | 0 0
  1. # $ pip install -r requirements.txt
  2.  
  3.  
  4. # $ python BTC_Finder.py
  5.  
  6. #  found.txt
  7.  
  8.  
  9.  
  10.  
  11. import requests
  12. import os
  13. import binascii
  14. import ecdsa
  15. import hashlib
  16. import base58
  17. import time
  18. import sys
  19. import codecs
  20. import io
  21. import sys
  22. import argparse
  23. import logging
  24. import time
  25.  
  26.  
  27. from multiprocessing import Process, Queue
  28.  
  29. class pause: # Counts API failures for timeout
  30.     p = 0
  31.  
  32. def privateKey(): # Generates random 256 bit private key in hex format
  33.     return binascii.hexlify(os.urandom(32)).decode('utf-8')
  34.  
  35. def publicKey(privatekey): # Private Key -> Public Key
  36.     privatekey = binascii.unhexlify(privatekey)
  37.     s = ecdsa.SigningKey.from_string(privatekey, curve = ecdsa.SECP256k1)
  38.     return '04' + binascii.hexlify(s.verifying_key.to_string()).decode('utf-8')
  39.  
  40. def address(publickey): # Public Key -> Wallet Address
  41.     alphabet = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
  42.     c = '0'; byte = '00'; zero = 0
  43.     var = hashlib.new('ripemd160')
  44.     var.update(hashlib.sha256(binascii.unhexlify(publickey.encode())).digest())
  45.     a = (byte + var.hexdigest())
  46.     doublehash = hashlib.sha256(hashlib.sha256(binascii.unhexlify(a.encode())).digest()).hexdigest()
  47.     address = a + doublehash[0:8]
  48.     for char in address:
  49.         if (char != c):
  50.             break
  51.         zero += 1
  52.     zero = zero // 2
  53.     n = int(address, 16)
  54.     output = []
  55.     while (n > 0):
  56.         n, remainder = divmod (n, 58)
  57.         output.append(alphabet[remainder])
  58.     count = 0
  59.     while (count < zero):
  60.         output.append(alphabet[0])
  61.         count += 1
  62.     return ''.join(output[::-1])
  63.  
  64. def balance(address): # Query API for wallet balance
  65.     try:
  66.         API = requests.get("https://bitcoinlegacy.blockexplorer.com/api/addr/" + str(address) + "/balance")
  67.         if (API.status_code == 429):
  68.             pause.p += 1
  69.             if (pause.p >= 10):
  70.                 print ("\nUnable to connect to API after several attempts\nRetrying in 30 seconds\n")
  71.                 time.sleep(30)
  72.                 pause.p = 0
  73.                 return -1
  74.             print("\nHTTP Error Code: " + str(API.status_code) + "\n")
  75.             return -1
  76.         if (API.status_code != 200 and API.status_code != 400):
  77.             print("\nHTTP Error Code: " + str(API.status_code) + "\nRetrying in 5 seconds\n")
  78.             time.sleep(5)
  79.             return -1
  80.         balance = int(API.text)
  81.         pause.p = 0
  82.         return balance
  83.     except:
  84.         pause.p += 1
  85.         if (pause.p >= 10):
  86.             print ("\nUnable to connect to API after several attempts\nRetrying in 30 seconds\n")
  87.             time.sleep(30)
  88.             pause.p = 0  
  89.         return -1
  90.  
  91. def toWIF(privatekey): # Hex Private Key -> WIF format
  92.     var80 = "80" + str(privatekey)
  93.     var = hashlib.sha256(binascii.unhexlify(hashlib.sha256(binascii.unhexlify(var80)).hexdigest())).hexdigest()
  94.     return str(base58.b58encode(binascii.unhexlify(str(var80) + str(var[0:8]))))
  95.  
  96. def Plutus(): # Main Plutus Function
  97.     data = [0,0,0,0]
  98.     while True:
  99.         data[0] = privateKey()
  100.         data[1] = publicKey(data[0])
  101.         data[2] = address(data[1])
  102.         data[3] = balance(data[2])
  103.         if (data[3] == -1):
  104.             continue
  105.         if (data[3] == 0):
  106.             print("{:<34}".format(str(data[2])) + " = " + str(data[3]))
  107.         if (data[3] > 0):
  108.             print ("\naddress: " + str(data[2]) + "\n" +
  109.                    "private key: " + str(data[0]) + "\n" +
  110.                    "WIF private key: " + str(toWIF(str(data[0]))) + "\n" +
  111.                    "public key: " + str(data[1]).upper() + "\n" +
  112.                    "balance: " + str(data[3]) + "\n")
  113.             file = open("plutus.txt","a")
  114.             file.write("address: " + str(data[2]) + "\n" +
  115.                        "private key: " + str(data[0]) + "\n" +
  116.                        "WIF private key: " + str(toWIF(str(data[0]))) + "\n" +
  117.                        "public key: " + str(data[1]).upper() + "\n" +
  118.                        "balance: " + str(data[3]) + "\n" +
  119.                        "Donate to the author of this program: 112vq8eT295ekWeuNzyeKbGYbvAsAZYZGu\n\n")
  120.             file.close()
  121.  
  122. ### Multiprocessing Extension Made By skip420 ###
  123.            
  124. def put_dataset(queue):
  125.     while True:
  126.         if queue.qsize() > 100:
  127.             time.sleep(10)
  128.         else:
  129.             privatekey = privateKey()
  130.             publickey = publicKey(privatekey)
  131.             Address = address(publickey)
  132.             WIF = toWIF(privatekey)
  133.             dataset = (Address, privatekey, publickey, WIF)
  134.             queue.put(dataset, block = False)
  135.     return None
  136.  
  137. def worker(queue):
  138.     time.sleep(1)
  139.     while True:
  140.         if queue.qsize() > 0:
  141.             dataset = queue.get(block = True)
  142.             balan = balance(dataset[0])
  143.             process_balance(dataset, balan)
  144.         else:
  145.             time.sleep(3)
  146.     return None
  147.  
  148. def process_balance(dataset,balance):
  149.     if balance == -1 :
  150.         return None
  151.     elif balance == 0 :
  152.         print("{:<34}".format(str(dataset[0])) + " = " + str(balance))
  153.         return None
  154.     else:
  155.         addr = dataset[0]
  156.         privatekey = dataset[1]
  157.         publickey = dataset[2]
  158.         WIF = dataset[3]
  159.         file = open("plutus.txt","a")
  160.         file.write("address: " + str(addr) + "\n" +
  161.                    "private key: " + str(privatekey) + "\n" +
  162.                    "WIF private key: " + str(WIF) + "\n" +
  163.                    "public key: " + str(publickey).upper() + "\n" +
  164.                    "balance: " + str(balance) + "\n" +
  165.                    "Donate to the author of this program: 112vq8eT295ekWeuNzyeKbGYbvAsAZYZGu\n\n")
  166.         file.close()
  167.     return None
  168.  
  169. def multi():
  170.     processes = []
  171.     dataset = Queue()
  172.     datasetProducer = Process(target = put_dataset, args = (dataset,))
  173.     datasetProducer.daemon = True
  174.     processes.append(datasetProducer)
  175.     datasetProducer.start()
  176.     for core in range(4):
  177.         work = Process(target = worker, args = (dataset,))
  178.         work.deamon = True
  179.         processes.append(work)
  180.         work.start()
  181.     try:
  182.         datasetProducer.join()
  183.     except KeyboardInterrupt:
  184.         for process in processes:
  185.             process.terminate()
  186.         print('\n\n------------------------\nALL PROCESSES TERMINATED\n')
  187.  
  188. ### End of Multiprocessing Extension ###
  189.  
  190. def main():
  191.     if ("-m" in sys.argv):
  192.         print("\n-------- MULTIPROCESSING MODE ACTIVATED --------\n")
  193.         time.sleep(3)
  194.         print("\n|-------- Wallet Address --------| = Balance in Satoshi")
  195.         multi()
  196.     else:
  197.         print("\n|-------- Wallet Address --------| = Balance in Satoshi")
  198.         Plutus()
  199.  
  200. if __name__ == '__main__':
  201.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement