/*
* jabberwocky - a password suggester
*/
#include <u.h>
#include <libc.h>
static char *sets[] = {
['C'] "BCDFGHJKLMNPQRSTVWXYZ",
['V'] "AEIOU",
['c'] "bcdfghjklmnpqrstvwxyz",
['v'] "aeiou",
['n'] "0123456789",
['%'] "!@#$%^&*()-+_~|{}[]/<>:;'\"\\=",
};
char *
genpat(void)
{
int i, len;
char *pat, *p;
len = rand()%12;
len = (len < 8) ? 8 : len;
pat = malloc(len+1);
if (! pat) return nil;
for (i = 0, p = pat; i < len; i++, p++)
*p = "CVcvn%"[(rand()%6)];
*p = 0;
return pat;
}
char *
jabberwocky(char *pat)
{
char *p;
char *w, *jab;
jab = malloc(strlen(pat)+1);
for (p = pat, w = jab; p && *p && w; p++) {
if (strchr("CVcnv%", *p))
*w++ = sets[*p][rand()%strlen(sets[*p])];
}
*w = 0;
return jab;
}
void
usage(void)
{
print("%s [pattern]\npattern ::= {'C' | 'V' | 'c' | 'v' | 'n' | '%%' } | pattern\n", argv0);
}
main(int argc, char **argv)
{
char *jab;
srand(time(0)+getpid());
argv0 = argv[0];
ARGBEGIN{
case 'h':
usage();
exits("");
default:
break;
}ARGEND;
if (argc == 0)
print("%s\n", jabberwocky(genpat()));
else
do {
jab = jabberwocky(*argv);
print("%s\n", jab);
free(jab);
argc--;
argv++;
} while (argc);
exits(nil);
}
|