int main(int argc, char** argv) { bloom_t *b; unsigned long i = 0; unsigned int us; char *fn; char *p; if (argc != 3) { printf("usage: %s <filename> <sleep time (us)>\n", argv[0]); exit(1); } fn = argv[1]; us = strtol(argv[2], &p, 0); if (p == argv[2] || *p != 0) { printf("failed to parse sleep time\n"); exit(1); } b = bloom_open(fn); while (1) { bloom_sweep(b, i); usleep(us); i++; } }
static void setup(bloom_drv_t *driver, char *buf, int len) { long n; double e; char *filename; int size; int type; int index = 0; ei_decode_version(buf, &index, NULL); ei_decode_tuple_header(buf, &index, NULL); ei_get_type(buf, &index, &type, &size); filename = driver_alloc(size+1); ei_decode_string(buf, &index, filename); ei_decode_long(buf, &index, &n); ei_decode_double(buf, &index, &e); driver->bloom = bloom_open(filename, n, e); driver_free(filename); }
int main(int argc, char **argv) { int rank; int size; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size); printf("Moin. I'm process %d of %d processes.\n", rank, size); //FILE *ifile = stdin; //MPI_File ifile = stdin; MPI_File ifile; FILE *ofile = stdout; int c, spok = 0, aopt = 0; unsigned char *bopt = NULL, *iopt = NULL, *oopt = NULL; unsigned char *topt = NULL, *sopt = NULL, *popt = NULL; unsigned char *Wopt = NULL; while ((c = getopt(argc, argv, "ab:hi:o:p:s:t:W:")) != -1) { switch (c) { case 'a': aopt = 1; // open output file in append mode break; case 'b': bopt = optarg; // bloom filter file break; case 'i': iopt = optarg; // input file break; case 'o': oopt = optarg; // output file break; case 's': sopt = optarg; // salt break; case 'p': popt = optarg; // passphrase break; case 't': topt = optarg; // type of input break; case 'W': Wopt = optarg; break; case 'h': // show help usage(argv[0]); return 0; case '?': // show error return 1; default: // should never be reached... printf("got option '%c' (%d)\n", c, c); return 1; } } if (optind < argc) { if (optind == 1 && argc == 2) { // older versions of brainflayer had the bloom filter file as a // single optional argument, this keeps compatibility with that bopt = argv[1]; } else { fprintf(stderr, "Invalid arguments:\n"); while (optind < argc) { fprintf(stderr, " '%s'\n", argv[optind++]); } exit(1); } } if (topt != NULL) { if (strcmp(topt, "str") == 0) { input2hash160 = &pass2hash160; } else if (strcmp(topt, "hex") == 0) { input2hash160 = &hexpass2hash160; } else if (strcmp(topt, "priv") == 0) { input2hash160 = &hexpriv2hash160; } else if (strcmp(topt, "warp") == 0) { spok = 1; input2hash160 = popt ? &warpsalt2hash160 : &warppass2hash160; } else if (strcmp(topt, "bwio") == 0) { spok = 1; if (popt && strcmp(popt, "hello world") == 0 && (Wopt == NULL || strcmp(Wopt, "NEVER_TELL_ME_THE_ODDS") != 0)) { // https://www.youtube.com/watch?v=NHWjlCaIrQo for (c = 0; c < 100; ++c) fprintf(stderr, "\n"); // try not to clobber scrollback fprintf(stderr, "\033[2J\033[0;0H\033[0;0f"); // clear terminal and send cursor to top left fflush(stderr); sleep(1); fprintf(stderr, "A STRANGE GAME.\n"); sleep(2); fprintf(stderr, "THE ONLY WINNING MOVE IS NOT TO PLAY.\n"); sleep(2); fprintf(stderr, "\n" "So, you're looking for that sweet, sweet 0.5BTC bounty? Brainflayer's\n" "cracking speed against brainwallet.io had been communicated to them before\n" "the challange was created. It is likely that the salt was chosen to be\n" "infeasible to crack in the given timeframe by a significant margin. I advise\n" "against trying it - it's probably a waste time and money. If you want to do it\n" "anyway, run with `-W NEVER_TELL_ME_THE_ODDS`.\n"); sleep(2); fprintf(stderr, "\nAs for me, I have better things to do with my CPU cycles.\n"); sleep(3); bail(83, "CONNECTION TERMINATED\n"); } input2hash160 = popt ? &bwiosalt2hash160 : &bwiopass2hash160; } else if (strcmp(topt, "bv2") == 0) { spok = 1; input2hash160 = popt ? &brainv2salt2hash160 : &brainv2pass2hash160; } else { bail(1, "Unknown input type '%s'.\n", topt); } } else { topt = "str"; input2hash160 = &pass2hash160; } if (spok) { if (sopt && popt) { bail(1, "Cannot specify both a salt and a passphrase\n"); } if (popt) { kdfpass = popt; kdfpass_sz = strlen(popt); } else { if (sopt) { kdfsalt = sopt; kdfsalt_sz = strlen(kdfsalt); } else { kdfsalt = malloc(0); kdfsalt_sz = 0; } } } else { if (popt) { bail(1, "Specifying a passphrase not supported with input type '%s'\n", topt); } else if (sopt) { bail(1, "Specifying a salt not supported with this input type '%s'\n", topt); } } if (bopt) { if ((bloom = bloom_open(bopt)) == NULL) { bail(1, "failed to open bloom filter.\n"); } } if (iopt) { if (MPI_File_open(MPI_COMM_WORLD, iopt, MPI_MODE_RDONLY, MPI_INFO_NULL, &ifile)) { bail(1, "failed to open '%s' for reading: %s\n", iopt, strerror(errno)); } } if (oopt) { if ((ofile = fopen(oopt, (aopt ? "a" : "w"))) == NULL) { bail(1, "failed to open '%s' for writing: %s\n", oopt, strerror(errno)); } } /* use line buffered output */ setvbuf(ofile, NULL, _IOLBF, 0); setvbuf(stderr, NULL, _IONBF, 0); secp256k1_start(); const int overlap = 100; char **lines; int nlines; readlines(&ifile, rank, size, overlap, &lines, &nlines); fprintf(ofile, "----Welcome %d! %d Lines for you.----\n", rank, nlines); int index = 0; time_t start, end; double length; time(&start); for (int i = 0; i < nlines - 1; i++) { ++index; input2hash160(lines[i], strlen(lines[i])); if (bloom) { if (bloom_chk_hash160(bloom, hash160_uncmp.ul)) { fprintresult(ofile, &hash160_uncmp, 'u', topt, lines[i]); } if (bloom_chk_hash160(bloom, hash160_compr.ul)) { fprintresult(ofile, &hash160_compr, 'c', topt, lines[i]); } } else { fprintresult(ofile, &hash160_uncmp, 'u', topt, lines[i]); fprintresult(ofile, &hash160_compr, 'c', topt, lines[i]); } } time(&end); length = difftime(end, start); double perSecond = index / length; fprintf(ofile, "----Process: %d, Lines: %d, speed: %.0f/sec!----\n", rank, index, perSecond); secp256k1_stop(); MPI_File_close(&ifile); MPI_Finalize(); return 0; }
int main(int argc, char **argv) { char *line = NULL; size_t line_sz = 0; secp256k1_start(); /* use line buffered output */ setvbuf(stdout, NULL, _IOLBF, 0); setvbuf(stderr, NULL, _IONBF, 0); if (argc == 2) { if ((bloom = bloom_open(argv[1])) == NULL) { fprintf(stderr, "failed to open bloom filter.\n"); exit(1); } } else if (argc > 2) { fprintf(stderr, "too many arguments\n"); exit(1); } while (getline(&line, &line_sz, stdin) > 0) { line[strlen(line)-1] = 0; pass2hash160(line, strlen(line)); if (argc == 2) { if (bloom_chk_hash160(bloom, hash160_uncmp.ul)) { fprintf(stdout, "matched: %08x%08x%08x%08x%08x:u:%s\n", ntohl(hash160_uncmp.ul[0]), ntohl(hash160_uncmp.ul[1]), ntohl(hash160_uncmp.ul[2]), ntohl(hash160_uncmp.ul[3]), ntohl(hash160_uncmp.ul[4]), line); } if (bloom_chk_hash160(bloom, hash160_compr.ul)) { fprintf(stdout, "matched: %08x%08x%08x%08x%08x:c:%s\n", ntohl(hash160_compr.ul[0]), ntohl(hash160_compr.ul[1]), ntohl(hash160_compr.ul[2]), ntohl(hash160_compr.ul[3]), ntohl(hash160_compr.ul[4]), line); } } else { fprintf(stdout, "%08x%08x%08x%08x%08x:u:%s\n", ntohl(hash160_uncmp.ul[0]), ntohl(hash160_uncmp.ul[1]), ntohl(hash160_uncmp.ul[2]), ntohl(hash160_uncmp.ul[3]), ntohl(hash160_uncmp.ul[4]), line); fprintf(stdout, "%08x%08x%08x%08x%08x:c:%s\n", ntohl(hash160_compr.ul[0]), ntohl(hash160_compr.ul[1]), ntohl(hash160_compr.ul[2]), ntohl(hash160_compr.ul[3]), ntohl(hash160_compr.ul[4]), line); } } secp256k1_stop(); return 0; }