>>710
The problem with that is that it only uses one process.
Try this:
/* Copyright (c) 2009 Xarn
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <getopt.h>
#include <signal.h>
#include <string.h>
#include <time.h>
#include <openssl/des.h>
#ifndef _GNU_SOURCE
#define strcasestr strstr
#endif
int checked = 0, /* # tripcodes examined so far */
p_id = 0, /* Process ID */
t; /* Starting time */
void salten(const char*, char*);
void done(int);
int main(int argc, char **argv)
{
int a, b, c, d, e, f, g, h, /* ins indices */
i, /* General loop variable */
procs = 4, /* Number of processes to use */
pstart, pstop, /* Search domain for the process */
do_random = 0; /* Random starting point? */
char cap[9], /* Capword */
salt[2], /* Crypt salt */
ret[14], /* DES_fcrypt buffer */
*trip = ret + 3, /* Actual tripcode */
opt;
extern char *optarg;
const char *ins = "!$%'()*+,-./0123456789:;<=>?@AB"
"CDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`"
"abcdefghijklmnopqrstuvwxyz{|}~",
*target = argv[argc - 1]; /* Search target */
const int len_ins = strlen(ins),
len_targ = strlen(target);
cap[8] = ret[13] = 0;
if (argc < 2) {
printf("Usage: %s [ -r ] [ -p PROCS ] STRING\n", argv[0]);
return 1;
}
/* Associate the signal handler. */
signal(SIGINT, *done);
/* Parse options */
while ((opt = getopt(argc, argv, "rp:")) != -1) {
switch (opt) {
case 'r':
do_random = 1;
break;
case 'p':
procs = atoi(optarg);
break;
}
}
/* Validate target */
for (i = 0; i < len_targ; ++i) {
if ((target[i] < 'A' || target[i] > 'Z') &&
(target[i] < 'a' || target[i] > 'z') &&
target[i] != '/' && target[i] != '.') {
fprintf(stderr,
"Invalid target \033[1m%s\033[0m: not in [a-zA-Z./].\n",
target);
return 2;
}
}
/* Determine the number of processes to use... */
if (procs < 1) procs = 1;
pstart = pstop = procs;
/* ... and spawn them. */
if (--procs) {
i = fork();
while (i != 0 && --procs) {
++p_id;
i = fork();
}
if (i != 0) ++p_id;
}
/* Find a sensible starting point for the process's search. */
pstart = len_ins / pstart * p_id;
pstop = len_ins / pstop * (p_id + 1);
if (do_random) {
FILE *randf = fopen("/dev/urandom", "r");
if (randf == NULL) {
fprintf(stderr, "Error: can't open /dev/urandom. Broken OS?\n");
srand((unsigned int)(time(NULL) + pstart));
pstart = rand();
} else {
fread((void *)&pstart, sizeof(int), 1, randf);
fclose(randf);
}
pstart = (unsigned int)pstart % len_ins;
}
/* Almost ready to begin! */
fprintf(stderr, "[%d] Starting at %c.\n", p_id, ins[pstart]);
t = (int)time(NULL);
/* Main loop(s) */
for (b = pstart; b < pstop; ++b) { cap[1] = ins[b];
for (c = 0; c < len_ins; ++c) { cap[2] = ins[c]; salten(cap, salt);
for (a = 0; a < len_ins; ++a) { cap[0] = ins[a];
for (d = 0; d < len_ins; ++d) { cap[3] = ins[d];
for (e = 0; e < len_ins; ++e) { cap[4] = ins[e];
for (f = 0; f < len_ins; ++f) { cap[5] = ins[f];
for (g = 0; g < len_ins; ++g) { cap[6] = ins[g];
for (h = 0; h < len_ins; ++h) { cap[7] = ins[h];
DES_fcrypt(cap, salt, ret);
if (strcasestr(trip, target) != NULL)
printf("%s -> %s\n", cap, trip);
++checked;
}}}}}}}} /* FROZENVOID QUALITY */
done(0);
return 0;
}
void salten(const char *cap, char *salt)
{
const char salt_table[128] =
".............................................../0123456789ABCDEF"
"GABCDEFGHIJKLMNOPQRSTUVWXYZabcdefabcdefghijklmnopqrstuvwxyz.....";
salt[0] = salt_table[(int)cap[1]];
salt[1] = salt_table[(int)cap[2]];
}
void done(int sig)
{
/* Signal handler. Performed upon SIGINT. */
t = (int)time(NULL) - t;
fprintf(stderr,
"[%d] %d tripcodes examined in %d seconds (%d per second).\n",
p_id, checked, t, checked / t);
exit(sig);
}
(To compile,
gcc -D_GNU_SOURCE -lssl file.c. Ubanto users and similar will want the
libssl-dev package, everyone else is assumed to know what they're doing.
Omitting
-D_GNU_SOURCE will make the search case sensitive, because
strcasestr is a GNU extension. It's ANSI C otherwise, so it should compile on any sensible system.
It's still slower than many moonspeak alternatives because it uses OpenSSL's
crypt instead of a bitslicing one, but more useful if you have a Beowulf cluster lying around.)