-
Notifications
You must be signed in to change notification settings - Fork 1
/
spew.c
105 lines (104 loc) · 2.71 KB
/
spew.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include <inttypes.h>
#include <math.h>
#include <help.h>
#include <password.h>
static char *alphanum="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
void spew(uint_fast64_t n, uint_fast32_t l, uint_fast32_t slots, uint_fast32_t assigned, uint_fast32_t offset, char* prefix)
{
if(slots && (n-offset) % slots >= assigned) { //if start value is not an "assigned line",
n=(n/slots+1)*slots-offset; //bump up to next "assigned line"
}
add(n);
uint_fast32_t skip=slots-assigned;
while(1) {
if((n-offset) % slots < assigned) { //there's probably a way to make this cheaper. it's in a pretty speed-critical section.
printpass();
n++;
add(1);
}
else {
if(debug) { //how much are these debug checks costing? this one is only slightly less critical than the ones in password.c
printf("%u - skipping %u\n", (unsigned int)n, (unsigned int)skip);
}
add(skip);
n+=skip;
}
}
}
void main(int argc, char **argv)
{
bool numeric=0;
uint_fast64_t start=0;
uint_fast32_t slots=1;
uint_fast32_t assigned=1;
uint_fast32_t offset=0;
uint_fast32_t length=1;
char *prefix="";
numeric=0;
setCharset(alphanum);
while (1) {
static struct option long_options[] = {
{"charset", required_argument, 0, 99 }, //c
{"numeric", no_argument, 0, 110 }, //n
{"alphanum", no_argument, 0, 97 }, //a
{"resume", required_argument, 0, 114 }, //r
{"blocksize", required_argument, 0, 116 }, //b
{"length", required_argument, 0, 101 }, //e
{"my-lines", required_argument, 0, 108 }, //l
{"offset-lines", required_argument, 0, 111 }, //o
{"debug", optional_argument, 0, 100 }, //d
{"prefix", required_argument, 0, 112 }, //p
{0, 0, 0, 0 }
};
char c = getopt_long(argc, argv, "c:nar:b:e:l:o:d::p:", long_options, 0);
if (c == -1) {
break;
}
switch (c) {
case 'c':
setCharset(optarg);
numeric=0;
break;
case 'n':
setCharset("0123456789");
numeric=1;
break;
case 'a':
setCharset(alphanum);
numeric=0;
break;
case 'r':
start=strtoumax(optarg,NULL,10);
break;
case 'b':
slots=strtoul(optarg,NULL,10);
break;
case 'e':
length=strtoul(optarg,NULL,10);
break;
case 'l':
assigned=strtoul(optarg,NULL,10);
break;
case 'o':
offset=strtoul(optarg,NULL,10);
break;
case 'd':
debug=1;
break;
case 'p':
setPrefix(optarg);
break;
default:
fprintf(stderr, HELP_MSG);
exit(1);
}
}
initpass(length);
spew(start, length, slots, assigned, offset, prefix);
}