Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  1
Language: C/C++
Code:
/*
 * Vanitygen, vanity bitcoin address generator
 * Copyright (C) 2011 <[email protected]>
 *
 * Vanitygen is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 *
 * Vanitygen is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with Vanitygen.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <assert.h>

#include <openssl/ec.h>
#include <openssl/bn.h>
#include <openssl/rand.h>

#include "oclengine.h"
#include "pattern.h"
#include "util.h"

#include "ticker.h"
char ticker[10];

int GRSFlag = 0;

const char *version = VANITYGEN_VERSION;
const int debug = 0;


void
usage(const char *name)
{
     fprintf(stderr,
"oclVanitygen %s (" OPENSSL_VERSION_TEXT ")n"
"Usage: %s [-vqrik1NTS] [-d <device>] [-f <filename>|-] [<pattern>...]n"
"Generates a bitcoin receiving address matching <pattern>, and outputs then"
"address and associated private key.  The private key may be stored in a safen"
"location or imported into a bitcoin client to spend any balance received onn"
"the address.n"
"By default, <pattern> is interpreted as an exact prefix.n"
"By default, if no device is specified, and the system has exactly one OpenCLn"
"device, it will be selected automatically, otherwise if the system hasn"
"multiple OpenCL devices and no device is specified, an error will ben"
"reported.  To use multiple devices simultaneously, specify the -D option forn"
"each device.n"
"n"
"Options:n"
"-v            Verbose outputn"
"-q            Quiet outputn"
"-r            Use regular expression match instead of prefixn"
"              (Feasibility of expression is not checked)n"
"-i            Case-insensitive prefix searchn"
"-k            Keep pattern and continue search after finding a matchn"
"-1            Stop after first matchn"
"-C <altcoin>  Generate an address for specific altcoin, use "-C LIST" to viewn"
"              a list of all available altcoins, argument is case sensitive!n"
"-X <version>  Generate address with the given versionn"
"-Y <version>  Specify private key version (-X provides public key)n"
"-F <format>   Generate address with the given format (pubkey, compressed)n"
"-P <pubkey>   Use split-key method with <pubkey> as base public keyn"
"-e            Encrypt private keys, prompt for passwordn"
"-E <password> Encrypt private keys with <password> (UNSAFE)n"
"-p <platform> Select OpenCL platformn"
"-d <device>   Select OpenCL devicen"
"-D <devstr>   Use OpenCL device, identified by device stringn"
"              Form: <platform>:<devicenumber>[,<options>]n"
"              Example: 0:0,grid=1024x1024n"
"-S            Safe mode, disable OpenCL loop unrolling optimizationsn"
"-w <worksize> Set work items per thread in a work unitn"
"-t <threads>  Set target thread count per multiprocessorn"
"-g <x>x<y>    Set grid sizen"
"-b <invsize>  Set modular inverse ops per threadn"
"-V            Enable kernel/OpenCL/hardware verification (SLOW)n"
"-f <file>     File containing list of patterns, one per linen"
"              (Use "-" as the file name for stdin)n"
"-o <file>     Write pattern matches to <file>n"
"-s <file>     Seed random number generator from <file>n",
version, name);
}

#define MAX_DEVS 32
#define MAX_FILE 4

int
main(int argc, char **argv)
{
     int addrtype = 0;
     int privtype = 128;
     int regex = 0;
     int caseinsensitive = 0;
     int opt;
     char pwbuf[128];
     int platformidx = -1, deviceidx = -1;
     int prompt_password = 0;
     char *seedfile = NULL;
     char **patterns, *pend;
     int verbose = 1;
     int npatterns = 0;
     int nthreads = 0;
     int worksize = 0;
     int nrows = 0, ncols = 0;
     int invsize = 0;
     int remove_on_match = 1;
     int only_one = 0;
     int verify_mode = 0;
     int safe_mode = 0;
     vg_context_t *vcp = NULL;
     vg_ocl_context_t *vocp = NULL;
     EC_POINT *pubkey_base = NULL;
     const char *result_file = NULL;
     const char *key_password = NULL;
     char *devstrs[MAX_DEVS];
     int ndevstrs = 0;
     int opened = 0;

     FILE *pattfp[MAX_FILE], *fp;
     int pattfpi[MAX_FILE];
     int npattfp = 0;
     int pattstdin = 0;
     int compressed = 0;

     int i;

     while ((opt = getopt(argc, argv,
                    "vqrik1C:X:Y:F:eE:p:P:d:w:t:g:b:VSh?f:o:s:D:")) != -1) {
          switch (opt) {
          case 'r':
               regex = 1;
               break;
          case 'v':
               verbose = 2;
               break;
          case 'q':
               verbose = 0;
               break;
          case 'i':
               caseinsensitive = 1;
               break;
          case 'k':
               remove_on_match = 0;
               break;
          case '1':
               only_one = 1;
               break;

/*BEGIN ALTCOIN GENERATOR*/

          case 'C':
               strcpy(ticker, optarg);
               strcat(ticker, " ");
               /* Start AltCoin Generator */
               if (strcmp(optarg, "LIST")== 0) {
                    fprintf(stderr,
                         "Usage example "./oclvanitygen -C LTC Lfoo"n"
                         "List of Available Alt-Coins for Address Generationn"
                         "---------------------------------------------------n"
                         "Argument(UPPERCASE) : Coin : Address Prefixn"
                         "---------------n"
                         "42 : 42coin : 4n"
                         "AC : Asiacoin : An"
                         "AIB : Advanced Internet Block by IOBOND : An"
                         "ANC : Anoncoin : An"
                         "ARS : Arkstone : An"
                         "ATMOS : Atmos : Nn"
                         "AUR : Auroracoin : An"
                         "AXE : Axe : Xn"
                         "BLK : Blackcoin : Bn"
                         "BQC : BBQcoin : bn"
                         "BTC : Bitcoin : 1n"
                         "TEST : Bitcoin Testnet : m or nn"
                         "BTCD : Bitcoin Dark : Rn"
                         "CCC : Chococoin : 7n"
                         "CCN : Cannacoin : Cn"
                         "CDN : Canadaecoin : Cn"
                         "CLAM : Clamcoin : xn"
                         "CNC : Chinacoin : Cn"
                         "CNOTE : C-Note : Cn"
                         "CON : PayCon : Pn"
                         "CRW : Crown : 1n"
                         "DASH : Dash : Xn"
                         "DEEPONION : DeepOnion : Dn"
                         "DNR: Denarius: Dn"
                         "DGB : Digibyte : Dn"
                         "DGC : Digitalcoin : Dn"
                         "DMD : Diamond : dn"
                         "DOGED : Doge Dark Coin : Dn"
                         "DOGE : Dogecoin : Dn"
                         "DOPE : Dopecoin : 4n"
                         "DVC : Devcoin : 1n"
                         "EFL : Electronic-Gulden-Foundation : Ln"
                         "EMC : Emercoin : En"
                         "FAIR : Faircoin2 : fn"
                         "FLOZ : FLOZ : Fn"
                         "FTC : Feathercoin : 6 or 7n"
                         "GAME : GameCredits : Gn"
                         "GAP : Gapcoin : Gn"
                         "GCR : Global Currency Reserve : Gn"
                         "GRC : GridcoinResearch : R or Sn"
                         "GRLC : Garlicoin : Gn"
                         "GRS : Groestlcoin : Fn"
                         "GUN : Guncoin : G or Hn"
                         "HAM : HamRadiocoin : 1n"
                         "HBN : HoboNickels(BottleCaps) : E or Fn"
                         "HODL : HOdlcoin : Hn"
                         "IXC : Ixcoin : xn"
                         "JBS : Jumbucks : Jn"
                         "JIN : Jincoin : Jn"
                         "LBRY : LBRY : bn"
                         "LEAF : Leafcoin : fn"
                         "LTC : Litecoin : Ln"
                         "MMC : Memorycoin : Mn"
                         "MONA : Monacoin : Mn"
                         "MUE : Monetary Unit : 7n"
                         "MYRIAD : Myriadcoin : Mn"
                         "MZC : Mazacoin : Mn"
                         "NEET : NEETCOIN : Nn"
                         "NEOS : Neoscoin : Sn"
                         "NLG : Gulden : Gn"
                         "NMC : Namecoin : M or Nn"
                         "NVC : Novacoin : 4n"
                         "NYAN : Nyancoin : Kn"
                         "OK : OK Cash : Pn"
                         "OMC : Omnicoin : on"
                         "PIGGY : Piggycoin : pn"
                         "PINK : Pinkcoin : 2n"
                         "PIVX : PIVX : Dn"
                         "PKB : Parkbyte : Pn"
                         "PND : Pandacoin : Pn"
                         "POT : Potcoin : Pn"
                         "PPC : Peercoin : Pn"
                         "PTC : Pesetacoin : Kn"
                         "PTS : Protoshares : Pn"
                         "QTUM : Qtum : Qn"
                         "RBY : Rubycoin : Rn"
                         "RDD : Reddcoin : Rn"
                         "RIC : Riecoin : Rn"
                         "ROI : ROIcoin : Rn"
                         "SCA : Scamcoin : Sn"
                         "SDC : Shadowcoin : Sn"
                         "SKC : Skeincoin : Sn"
                         "SPR : Spreadcoin : Sn"
                         "START : Startcoin : sn"
                         "SXC : Sexcoin : R or Sn"
                         "TPC : Templecoin : Tn"
                         "UIS : Unitus : Un"
                         "UNO : Unobtanium : un"
                         "VIA : Viacoin : Vn"
                         "VPN : Vpncoin : Vn"
                         "VTC : Vertcoin : Vn"
                         "WDC : Worldcoin Global : Wn"
                         "WKC : Wankcoin : 1n"
                         "WUBS : Dubstepcoin : Dn"
                         "XC : XCurrency : Xn"
                         "XPM : Primecoin : An"
                         "YAC : Yacoin : Yn"
                         "ZNY : BitZeny : Zn"
                         "ZOOM : Zoom coin : in"
                         "ZRC : Ziftrcoin : Zn"
                         );
                         return 1;
               }
               else
               if (strcmp(optarg, "PIVX")== 0) {
                    fprintf(stderr,
                         "Generating PIVX Addressn");
                         addrtype = 30;
                         privtype = 212;
                         break;
               }
               else
               if (strcmp(optarg, "PINK")== 0) {
                    fprintf(stderr,
                         "Generating PINK Addressn");
                         addrtype = 3;
                         privtype = 131;
                         break;
               }
               else
               if (strcmp(optarg, "DEEPONION")== 0) {
                    fprintf(stderr,
                         "Generating DEEPONION Addressn");
                         addrtype = 31;
                         privtype = 159;
                         break;
               }
               else
               if (strcmp(optarg, "DNR")== 0) {
                    fprintf(stderr,
                         "Generating DNR Addressn");
                         addrtype = 30;
                         privtype = 158;
                         break;
               }
               else
               if (strcmp(optarg, "DMD")== 0) {
                    fprintf(stderr,
                         "Generating DMD Addressn");
                         addrtype = 90;
                         privtype = 218;
                         break;
               }
               else
               if (strcmp(optarg, "GRS")== 0) {
                    fprintf(stderr,
                         "Generating GRS Addressn");
                         GRSFlag = 1;
                         addrtype = 36;
                         privtype = 128;
                         break;
               }
               else
               if (strcmp(optarg, "GUN")== 0) {
                    fprintf(stderr,
                         "Generating GUN Addressn");
                         addrtype = 39;
                         privtype = 167;
                         break;
               }
               else
               if (strcmp(optarg, "HAM")== 0) {
                    fprintf(stderr,
                         "Generating HAM Addressn");
                         addrtype = 0;
                         privtype = 128;
                         break;
               }
               else
               if (strcmp(optarg, "DVC")== 0) {
                    fprintf(stderr,
                         "Generating DVC Addressn");
                         addrtype = 0;
                         privtype = 128;
                         break;
               }
               else
               if (strcmp(optarg, "42")== 0) {
                    fprintf(stderr,
                         "Generating 42 Addressn");
                         addrtype = 8;
                         privtype = 136;
                         break;
               }
               else
               if (strcmp(optarg, "WKC")== 0) {
                    fprintf(stderr,
                         "Generating WKC Addressn");
                         addrtype = 0;
                         privtype = 128;
                         break;
               }
               else
               if (strcmp(optarg, "SPR")== 0) {
                    fprintf(stderr,
                         "Generating SPR Addressn");
                         addrtype = 63;
                         privtype = 191;
                         break;
               }
               else
               if (strcmp(optarg, "SCA")== 0) {
                    fprintf(stderr,
                         "Generating SCA Addressn");
                         addrtype = 63;
                         privtype = 191;
                         break;
               }
               else
               if (strcmp(optarg, "GAP")== 0) {
                    fprintf(stderr,
                         "Generating GAP Addressn");
                         addrtype = 38;
                         privtype = 166;
                         break;
               }
               else
               if (strcmp(optarg, "CCC")== 0) {
                    fprintf(stderr,
                         "Generating CCC Addressn");
                         addrtype = 15;
                         privtype = 224;
                         break;
               }
               else
               if (strcmp(optarg, "PIGGY")== 0) {
                    fprintf(stderr,
                         "Generating PIGGY Addressn");
                         addrtype = 118;
                         privtype = 246;
                         break;
               }
               else
               if (strcmp(optarg, "WDC")== 0) {
                    fprintf(stderr,
                         "Generating WDC Addressn");
                         addrtype = 73;
                         privtype = 201;
                         break;
               }
               else
               if (strcmp(optarg, "XC")== 0) {
                    fprintf(stderr,
                         "Generating XC Addressn");
                         addrtype = 75;
                         privtype = 203;
                         break;
               }
               else
               if (strcmp(optarg, "WUBS")== 0) {
                    fprintf(stderr,
                         "Generating WUBS Addressn");
                         addrtype = 29;
                         privtype = 157;
                         break;
               }
               else
               if (strcmp(optarg, "SXC")== 0) {
                    fprintf(stderr,
                         "Generating SXC Addressn");
                         addrtype = 62;
                         privtype = 190;
                         break;
               }
               else
               if (strcmp(optarg, "SKC")== 0) {
                    fprintf(stderr,
                         "Generating SKC Addressn");
                         addrtype = 63;
                         privtype = 226;
                         break;
               }
               else
               if (strcmp(optarg, "PTS")== 0) {
                    fprintf(stderr,
                         "Generating PTS Addressn");
                         addrtype = 56;
                         privtype = 184;
                         break;
               }
               else
               if (strcmp(optarg, "NLG")== 0) {
                    fprintf(stderr,
                         "Generating NLG Addressn");
                         addrtype = 38;
                         privtype = 166;
                         break;
               }
               else
               if (strcmp(optarg, "MMC")== 0) {
                    fprintf(stderr,
                         "Generating MMC Addressn");
                         addrtype = 50;
                         privtype = 178;
                         break;
               }
               else
               if (strcmp(optarg, "LEAF")== 0) {
                    fprintf(stderr,
                         "Generating LEAF Addressn");
                         addrtype = 95;
                         privtype = 223;
                         break;
               }
               else
               if (strcmp(optarg, "ROI")== 0) {
                    fprintf(stderr,
                         "Generating ROI Addressn");
                         addrtype = 60;
                         privtype = 128;
                         break;
               }
               else
               if (strcmp(optarg, "HODL")== 0) {
                    fprintf(stderr,
                         "Generating HODL Addressn");
                         addrtype = 40;
                         privtype = 168;
                         break;
               }
               else
               if (strcmp(optarg, "FLOZ")== 0) {
                    fprintf(stderr,
                         "Generating FLOZ Addressn");
                         addrtype = 35;
                         privtype = 163;
                         break;
               }
               else
               if (strcmp(optarg, "FAIR")== 0) {
                    fprintf(stderr,
                         "Generating FAIR Addressn");
                         addrtype = 95;
                         privtype = 223;
                         break;
               }
               else
               if (strcmp(optarg, "CON")== 0) {
                    fprintf(stderr,
                         "Generating CON Addressn");
                         addrtype = 55;
                         privtype = 183;
                         break;
               }
               else
               if (strcmp(optarg, "AUR")== 0) {
                    fprintf(stderr,
                         "Generating AUR Addressn");
                         addrtype = 23;
                         privtype = 151;
                         break;
               }
               else
               if (strcmp(optarg, "GRC")== 0) {
                    fprintf(stderr,
                         "Generating GRC Addressn");
                         addrtype = 62;
                         privtype = 190;
                         break;
               }
               else
               if (strcmp(optarg, "RIC")== 0) {
                    fprintf(stderr,
                         "Generating RIC Addressn");
                         addrtype = 60;
                         privtype = 128;
                         break;
               }
               else
               if (strcmp(optarg, "UNO")== 0) {
                    fprintf(stderr,
                         "Generating UNO Addressn");
                         addrtype = 130;
                         privtype = 224;
                         break;
               }
               else
               if (strcmp(optarg, "UIS")== 0) {
                    fprintf(stderr,
                         "Generating UIS Addressn");
                         addrtype = 68;
                         privtype = 132;
                         break;
               }
               else
               if (strcmp(optarg, "MYRIAD")== 0) {
                    fprintf(stderr,
                         "Generating MYRIAD Addressn");
                         addrtype = 50;
                         privtype = 178;
                         break;
               }
               else
               if (strcmp(optarg, "BQC")== 0) {
                    fprintf(stderr,
                         "Generating BQC Addressn");
                         addrtype = 85;
                         privtype = 213;
                         break;
               }
               else
               if (strcmp(optarg, "YAC")== 0) {
                    fprintf(stderr,
                         "Generating YAC Addressn");
                         addrtype = 77;
                         privtype = 205;
                         break;
               }
               else
               if (strcmp(optarg, "PTC")== 0) {
                    fprintf(stderr,
                         "Generating PTC Addressn");
                         addrtype = 47;
                         privtype = 175;
                         break;
               }
               else
               if (strcmp(optarg, "RDD")== 0) {
                    fprintf(stderr,
                         "Generating RDD Addressn");
                         addrtype = 61;
                         privtype = 189;
                         break;
               }
               else
               if (strcmp(optarg, "NYAN")== 0) {
                    fprintf(stderr,
                         "Generating NYAN Addressn");
                         addrtype = 45;
                         privtype = 173;
                         break;
               }
               else
               if (strcmp(optarg, "IXC")== 0) {
                    fprintf(stderr,
                         "Generating IXC Addressn");
                         addrtype = 138;
                         privtype = 266;
                         break;
               }
               else
               if (strcmp(optarg, "CNC")== 0) {
                    fprintf(stderr,
                         "Generating CNC Addressn");
                         addrtype = 28;
                         privtype = 156;
                         break;
               }
               else
               if (strcmp(optarg, "CNOTE")== 0) {
                    fprintf(stderr,
                         "Generating C-Note Addressn");
                         addrtype = 28;
                         privtype = 186;
                         break;
               }
               else
               if (strcmp(optarg, "ARS")== 0) {
                    fprintf(stderr,
                         "Generating ARS Addressn");
                         addrtype = 23;
                         privtype = 151;
                         break;
               }
               else
               if (strcmp(optarg, "ANC")== 0) {
                    fprintf(stderr,
                         "Generating ANC Addressn");
                         addrtype = 23;
                         privtype = 151;
                         break;
               }
               else
               if (strcmp(optarg, "OMC")== 0) {
                    fprintf(stderr,
                         "Generating OMC Addressn");
                         addrtype = 115;
                         privtype = 243;
                         break;
               }
               else
               if (strcmp(optarg, "POT")== 0) {
                    fprintf(stderr,
                         "Generating POT Addressn");
                         addrtype = 55;
                         privtype = 183;
                         break;
               }
               else
               if (strcmp(optarg, "EFL")== 0) {
                    fprintf(stderr,
                         "Generating EFL Addressn");
                         addrtype = 48;
                         privtype = 176;
                         break;
               }
               else
               if (strcmp(optarg, "EMC")== 0) {
                    fprintf(stderr,
                              "Generating Emercoin Addressn");
                    addrtype = 33;
                    privtype = 128;
                    break;
               }
               else
               if (strcmp(optarg, "DOGED")== 0) {
                    fprintf(stderr,
                         "Generating DOGED Addressn");
                         addrtype = 30;
                         privtype = 158;
                         break;
               }
               else
               if (strcmp(optarg, "OK")== 0) {
                    fprintf(stderr,
                         "Generating OK Addressn");
                         addrtype = 55;
                         privtype = 183;
                         break;
               }
               else
               if (strcmp(optarg, "AIB")== 0) {
                    fprintf(stderr,
                         "Generating AIB Addressn");
                         addrtype = 23;
                         privtype = 151;
                         break;
               }
               else
               if (strcmp(optarg, "TPC")== 0) {
                    fprintf(stderr,
                         "Generating TPC Addressn");
                         addrtype = 65;
                         privtype = 193;
                         break;
               }
               else
               if (strcmp(optarg, "DOPE")== 0) {
                    fprintf(stderr,
                         "Generating DOPE Addressn");
                         addrtype = 8;
                         privtype = 136;
                         break;
               }
               else
               if (strcmp(optarg, "BTCD")== 0) {
                    fprintf(stderr,
                         "Generating BTCD Addressn");
                         addrtype = 60;
                         privtype = 188;
                         break;
               }
               else
               if (strcmp(optarg, "AC")== 0) {
                    fprintf(stderr,
                         "Generating AC Addressn");
                         addrtype = 23;
                         privtype = 151;
                         break;
               }
               else
               if (strcmp(optarg, "NVC")== 0) {
                    fprintf(stderr,
                         "Generating NVC Addressn");
                         addrtype = 8;
                         privtype = 136;
                         break;
               }
               else
               if (strcmp(optarg, "HBN")== 0) {
                    fprintf(stderr,
                         "Generating HBN Addressn");
                         addrtype = 34;
                         privtype = 162;
                         break;
               }
               else
               if (strcmp(optarg, "GCR")== 0) {
                    fprintf(stderr,
                         "Generating GCR Addressn");
                         addrtype = 38;
                         privtype = 154;
                         break;
               }
               else
               if (strcmp(optarg, "START")== 0) {
                    fprintf(stderr,
                         "Generating START Addressn");
                         addrtype = 125;
                         privtype = 253;
                         break;
               }
               else
               if (strcmp(optarg, "PND")== 0) {
                    fprintf(stderr,
                         "Generating PND Addressn");
                         addrtype = 55;
                         privtype = 183;
                         break;
               }
               else
               if (strcmp(optarg, "PKB")== 0) {
                    fprintf(stderr,
                         "Generating PKB Addressn");
                         addrtype = 55;
                         privtype = 183;
                         break;
               }
               else
               if (strcmp(optarg, "SDC")== 0) {
                    fprintf(stderr,
                         "Generating SDC Addressn");
                         addrtype = 63;
                         privtype = 191;
                         break;
               }
               else
               if (strcmp(optarg, "CDN")== 0) {
                    fprintf(stderr,
                         "Generating CDN Addressn");
                         addrtype = 28;
                         privtype = 156;
                         break;
               }
               else
               if (strcmp(optarg, "VPN")== 0) {
                    fprintf(stderr,
                         "Generating VPN Addressn");
                         addrtype = 71;
                         privtype = 199;
                         break;
               }
               else
               if (strcmp(optarg, "ZOOM")== 0) {
                    fprintf(stderr,
                         "Generating ZOOM Addressn");
                         addrtype = 103;
                         privtype = 231;
                         break;
               }
               else
               if (strcmp(optarg, "MUE")== 0) {
                    fprintf(stderr,
                         "Generating MUE Addressn");
                         addrtype = 15;
                         privtype = 143;
                         break;
               }
               else
               if (strcmp(optarg, "VTC")== 0) {
                    fprintf(stderr,
                         "Generating VTC Addressn");
                         addrtype = 71;
                         privtype = 199;
                         break;
               }
               else
               if (strcmp(optarg, "ZRC")== 0) {
                    fprintf(stderr,
                         "Generating ZRC Addressn");
                         addrtype = 80;
                         privtype = 208;
                         break;
               }
               else
               if (strcmp(optarg, "JBS")== 0) {
                    fprintf(stderr,
                         "Generating JBS Addressn");
                         addrtype = 43;
                         privtype = 171;
                         break;
               }
               else
               if (strcmp(optarg, "JIN")== 0) {
                    fprintf(stderr,
                         "Generating JIN Addressn");
                         addrtype = 43;
                         privtype = 171;
                         break;
               }
               else
               if (strcmp(optarg, "NEOS")== 0) {
                    fprintf(stderr,
                         "Generating NEOS Addressn");
                         addrtype = 63;
                         privtype = 239;
                         break;
               }
               else
               if (strcmp(optarg, "XPM")== 0) {
                    fprintf(stderr,
                         "Generating XPM Addressn");
                         addrtype = 23;
                         privtype = 151;
                         break;
               }
               else
               if (strcmp(optarg, "CLAM")== 0) {
                    fprintf(stderr,
                         "Generating CLAM Addressn");
                         addrtype = 137;
                         privtype = 133;
                         break;
               }
               else
               if (strcmp(optarg, "MONA")== 0) {
                    fprintf(stderr,
                         "Generating MONA Addressn");
                         addrtype = 50;
                         privtype = 176;
                         break;
               }
               else
               if (strcmp(optarg, "DGB")== 0) {
                    fprintf(stderr,
                         "Generating DGB Addressn");
                         addrtype = 30;
                         privtype = 128;
                         break;
               }
               else
               if (strcmp(optarg, "CCN")== 0) {
                    fprintf(stderr,
                         "Generating CCN Addressn");
                         addrtype = 28;
                         privtype = 156;
                         break;
               }
               else
               if (strcmp(optarg, "DGC")== 0) {
                    fprintf(stderr,
                         "Generating DGC Addressn");
                         addrtype = 30;
                         privtype = 158;
                         break;
               }
               else
               if (strcmp(optarg, "RBY")== 0) {
                    fprintf(stderr,
                         "Generating RBY Addressn");
                         addrtype = 61;
                         privtype = 189;
                         break;
               }
               else
               if (strcmp(optarg, "VIA")== 0) {
                    fprintf(stderr,
                         "Generating VIA Addressn");
                         addrtype = 71;
                         privtype = 199;
                         break;
               }
               else
               if (strcmp(optarg, "MZC")== 0) {
                    fprintf(stderr,
                         "Generating MZC Addressn");
                         addrtype = 50;
                         privtype = 224;
                         break;
               }
               else
               if (strcmp(optarg, "BLK")== 0) {
                    fprintf(stderr,
                         "Generating BLK Addressn");
                         addrtype = 25;
                         privtype = 153;
                         break;
               }
               else
               if (strcmp(optarg, "FTC")== 0) {
                    fprintf(stderr,
                         "Generating FTC Addressn");
                         addrtype = 14;
                         privtype = 142;
                         break;
               }
               else
               if (strcmp(optarg, "PPC")== 0) {
                    fprintf(stderr,
                         "Generating PPC Addressn");
                         addrtype = 55;
                         privtype = 183;
                         break;
               }
               else
               if (strcmp(optarg, "DASH")== 0) {
                    fprintf(stderr,
                         "Generating DASH Addressn");
                         addrtype = 76;
                         privtype = 204;
                         break;
               }
               else
               if (strcmp(optarg, "BTC")== 0) {
                    fprintf(stderr,
                         "Generating BTC Addressn");
                         addrtype = 0;
                         privtype = 128;
                         break;
               }
               else
               if (strcmp(optarg, "TEST")== 0) {
                    fprintf(stderr,
                         "Generating BTC Testnet Addressn");
                         addrtype = 111;
                         privtype = 239;
                         break;
               }
               else
               if (strcmp(optarg, "DOGE")== 0) {
                    fprintf(stderr,
                         "Generating DOGE Addressn");
                         addrtype = 30;
                         privtype = 158;
                         break;
               }
               else
               if (strcmp(optarg, "LBRY")== 0) {
                    fprintf(stderr,
                         "Generating LBRY Addressn");
                         addrtype = 85;
                         privtype = 28;
                         break;
               }
               else
               if (strcmp(optarg, "LTC")== 0) {
                    fprintf(stderr,
                         "Generating LTC Addressn");
                         addrtype = 48;
                         privtype = 176;
                         break;
               }
               else
               if (strcmp(optarg, "GRLC")== 0) {
                    fprintf(stderr,
                         "Generating GRLC Addressn");
                         addrtype = 38;
                         privtype = 176;
                         break;
               }
               else
               if (strcmp(optarg, "NMC")== 0) {
                    fprintf(stderr,
                         "Generating NMC Addressn");
                         addrtype = 52;
                         privtype = 180;
                         break;
               }
               else
               if (strcmp(optarg, "GAME")== 0) {
                    fprintf(stderr,
                         "Generating GAME Addressn");
                         addrtype = 38;
                         privtype = 166;
                         break;
               }
               else
               if (strcmp(optarg, "CRW")== 0) {
                    fprintf(stderr,
                         "Generating CRW Addressn");
                         addrtype = 0;
                         privtype = 128;
                         break;
               }
               else
               if (strcmp(optarg, "QTUM")== 0) {
                    fprintf(stderr,
                         "Generating QTUM Addressn");
                         addrtype = 58;
                         privtype = 128;
                         break;
               }
               else
               if (strcmp(optarg, "ATMOS")== 0) {
                    fprintf(stderr,
                         "Generating ATMOS Addressn");
                         addrtype = 53;
                         privtype = 153;
                         break;
               }
               else
               if (strcmp(optarg, "AXE")== 0) {
                    fprintf(stderr,
                         "Decrypting AXE Addressn");
                         addrtype = 55;
                         privtype = 204;
                         break;
               }
               else
               if (strcmp(optarg, "ZNY")== 0) {
                    fprintf(stderr,
                         "Generating BitZeny Addressn");
                         addrtype = 81;
                         privtype = 128;
                         break;
               }
               else
               if (strcmp(optarg, "NEET")== 0) {
                    fprintf(stderr,
                         "Generating NEETCOIN Addressn");
                         addrtype = 53;
                         privtype = 181;
                         break;
               }
               break;

/*END ALTCOIN GENERATOR*/

          case 'X':
               addrtype = atoi(optarg);
               privtype = 128 + addrtype;
               break;
          case 'Y':
               /* Overrides privtype of 'X' but leaves all else intact */
               privtype = atoi(optarg);
               break;
          case 'F':
               if (!strcmp(optarg, "compressed"))
                    compressed = 1;
               else
               if (strcmp(optarg, "pubkey")) {
                    fprintf(stderr,
                         "Invalid format '%s'n", optarg);
                    return 1;
               }
               break;
          case 'e':
               prompt_password = 1;
               break;
          case 'E':
               key_password = optarg;
               break;
          case 'p':
               platformidx = atoi(optarg);
               break;
          case 'd':
               deviceidx = atoi(optarg);
               break;
          case 'w':
               worksize = atoi(optarg);
               if (worksize == 0) {
                    fprintf(stderr,
                         "Invalid work size '%s'n", optarg);
                    return 1;
               }
               break;
          case 't':
               nthreads = atoi(optarg);
               if (nthreads == 0) {
                    fprintf(stderr,
                         "Invalid thread count '%s'n", optarg);
                    return 1;
               }
               break;
          case 'g':
               nrows = 0;
               ncols = strtol(optarg, &pend, 0);
               if (pend && *pend == 'x') {
                    nrows = strtol(pend+1, NULL, 0);
               }
               if (!nrows || !ncols) {
                    fprintf(stderr,
                         "Invalid grid size '%s'n", optarg);
                    return 1;
               }
               break;
          case 'b':
               invsize = atoi(optarg);
               if (!invsize) {
                    fprintf(stderr,
                         "Invalid modular inverse size '%s'n",
                         optarg);
                    return 1;
               }
               if (invsize & (invsize - 1)) {
                    fprintf(stderr,
                         "Modular inverse size must be "
                         "a power of 2n");
                    return 1;
               }
               break;
          case 'V':
               verify_mode = 1;
               break;
          case 'S':
               safe_mode = 1;
               break;
          case 'D':
               if (ndevstrs >= MAX_DEVS) {
                    fprintf(stderr,
                         "Too many OpenCL devices (limit %d)n",
                         MAX_DEVS);
                    return 1;
               }
               devstrs[ndevstrs++] = optarg;
               break;
          case 'P': {
               if (pubkey_base != NULL) {
                    fprintf(stderr,
                         "Multiple base pubkeys specifiedn");
                    return 1;
               }
               EC_KEY *pkey = vg_exec_context_new_key();
               pubkey_base = EC_POINT_hex2point(
                    EC_KEY_get0_group(pkey),
                    optarg, NULL, NULL);
               EC_KEY_free(pkey);
               if (pubkey_base == NULL) {
                    fprintf(stderr,
                         "Invalid base pubkeyn");
                    return 1;
               }
               break;
          }
          case 'f':
               if (npattfp >= MAX_FILE) {
                    fprintf(stderr,
                         "Too many input files specifiedn");
                    return 1;
               }
               if (!strcmp(optarg, "-")) {
                    if (pattstdin) {
                         fprintf(stderr, "ERROR: stdin "
                              "specified multiple timesn");
                         return 1;
                    }
                    fp = stdin;
               } else {
                    fp = fopen(optarg, "r");
                    if (!fp) {
                         fprintf(stderr,
                              "Could not open %s: %sn",
                              optarg, strerror(errno));
                         return 1;
                    }
               }
               pattfp[npattfp] = fp;
               pattfpi[npattfp] = caseinsensitive;
               npattfp++;
               break;
          case 'o':
               if (result_file) {
                    fprintf(stderr,
                         "Multiple output files specifiedn");
                    return 1;
               }
               result_file = optarg;
               break;
          case 's':
               if (seedfile != NULL) {
                    fprintf(stderr,
                         "Multiple RNG seeds specifiedn");
                    return 1;
               }
               seedfile = optarg;
               break;
          default:
               usage(argv[0]);
               return 1;
          }
     }

#if OPENSSL_VERSION_NUMBER < 0x10000000L
     /* Complain about older versions of OpenSSL */
     if (verbose > 0) {
          fprintf(stderr,
               "WARNING: Built with " OPENSSL_VERSION_TEXT "n"
               "WARNING: Use OpenSSL 1.0.0d+ for best performancen");
     }
#endif

     if (caseinsensitive && regex)
          fprintf(stderr,
               "WARNING: case insensitive mode incompatible with "
               "regular expressionsn");

     if (seedfile) {
          opt = -1;
#if !defined(_WIN32)
          {     struct stat st;
               if (!stat(seedfile, &st) &&
                   (st.st_mode & (S_IFBLK|S_IFCHR))) {
                    opt = 32;
          } }
#endif
          opt = RAND_load_file(seedfile, opt);
          if (!opt) {
               fprintf(stderr, "Could not load RNG seed %sn", optarg);
               return 1;
          }
          if (verbose > 0) {
               fprintf(stderr,
                    "Read %d bytes from RNG seed filen", opt);
          }
     }

     if (regex) {
          vcp = vg_regex_context_new(addrtype, privtype);

     } else {
          vcp = vg_prefix_context_new(addrtype, privtype,
                             caseinsensitive);
     }

     vcp->vc_compressed = compressed;
     vcp->vc_verbose = verbose;
     vcp->vc_result_file = result_file;
     vcp->vc_remove_on_match = remove_on_match;
     vcp->vc_only_one = only_one;
     vcp->vc_pubkeytype = addrtype;
     vcp->vc_pubkey_base = pubkey_base;

     vcp->vc_output_match = vg_output_match_console;
     vcp->vc_output_timing = vg_output_timing_console;

     if (!npattfp) {
          if (optind >= argc) {
               usage(argv[0]);
               return 1;
          }
          patterns = &argv[optind];
          npatterns = argc - optind;

          if (!vg_context_add_patterns(vcp,
                              (const char ** const) patterns,
                              npatterns))
          return 1;
     }

     for (i = 0; i < npattfp; i++) {
          fp = pattfp[i];
          if (!vg_read_file(fp, &patterns, &npatterns)) {
               fprintf(stderr, "Failed to load pattern filen");
               return 1;
          }
          if (fp != stdin)
               fclose(fp);

          if (!regex)
               vg_prefix_context_set_case_insensitive(vcp, pattfpi[i]);

          if (!vg_context_add_patterns(vcp,
                              (const char ** const) patterns,
                              npatterns))
          return 1;
     }

     if (!vcp->vc_npatterns) {
          fprintf(stderr, "No patterns to searchn");
          return 1;
     }

     if (prompt_password) {
          if (!vg_read_password(pwbuf, sizeof(pwbuf)))
               return 1;
          key_password = pwbuf;
     }
     vcp->vc_key_protect_pass = key_password;
     if (key_password) {
          if (!vg_check_password_complexity(key_password, verbose))
               fprintf(stderr,
                    "WARNING: Protecting private keys with "
                    "weak passwordn");
     }

     if ((verbose > 0) && regex && (vcp->vc_npatterns > 1))
          fprintf(stderr,
               "Regular expressions: %ldn", vcp->vc_npatterns);

     if (ndevstrs) {
          for (opt = 0; opt < ndevstrs; opt++) {
               vocp = vg_ocl_context_new_from_devstr(vcp, devstrs[opt],
                                         safe_mode,
                                         verify_mode);
               if (!vocp) {
                    fprintf(stderr,
                    "Could not open device '%s', ignoringn",
                         devstrs[opt]);
               } else {
                    opened++;
               }
          }
     } else {
          vocp = vg_ocl_context_new(vcp, platformidx, deviceidx,
                           safe_mode, verify_mode,
                           worksize, nthreads,
                           nrows, ncols, invsize);
          if (vocp)
               opened++;
     }

     if (!opened) {
          vg_ocl_enumerate_devices();
          return 1;
     }

     opt = vg_context_start_threads(vcp);
     if (opt)
          return 1;

     vg_context_wait_for_completion(vcp);
     vg_ocl_context_free(vocp);
     return 0;
}

          
Comments: