Skip to content

Commit e8dc41d

Browse files
committed
recursive
1 parent 68d17be commit e8dc41d

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

src/zipcracker.cpp

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,13 @@ void showProgress(size_t totalPasswords) {
9999
}
100100

101101
size_t calculateTotalPasswords(int length, const std::string& charset) {
102-
size_t total = 1;
103-
for (int i = 0; i < length; ++i) {
104-
total *= charset.size();
102+
size_t total = 0;
103+
for (int i = 1; i <= length; ++i) {
104+
size_t count = 1;
105+
for (int j = 0; j < i; ++j) {
106+
count *= charset.size();
107+
}
108+
total += count;
105109
}
106110
return total;
107111
}
@@ -118,12 +122,14 @@ int main(int argc, char* argv[]) {
118122
{"length", required_argument, 0, 'l'},
119123
{"wordlist", required_argument, 0, 'w'},
120124
{"threads", required_argument, 0, 't'},
125+
{"recursive", no_argument, 0, 'r'},
121126
{0, 0, 0, 0}
122127
};
123128

124129
int option_index = 0;
125130
int opt;
126-
while ((opt = getopt_long(argc, argv, "f:l:w:t:", long_options, &option_index)) != -1) {
131+
bool recursive = false;
132+
while ((opt = getopt_long(argc, argv, "f:l:w:t:r", long_options, &option_index)) != -1) {
127133
switch (opt) {
128134
case 'f':
129135
file = optarg;
@@ -142,8 +148,11 @@ int main(int argc, char* argv[]) {
142148
return 1;
143149
}
144150
break;
151+
case 'r':
152+
recursive = true;
153+
break;
145154
default:
146-
std::cerr << "Verwendung: " << argv[0] << " -f <file> [-l <password-length>] [-w <wordlist>] [-t <thread-count>]" << std::endl;
155+
std::cerr << "Verwendung: " << argv[0] << " -f <file> [-l <password-length>] [-w <wordlist>] [-t <thread-count>] [-r]" << std::endl;
147156
return 1;
148157
}
149158
}
@@ -172,7 +181,13 @@ int main(int argc, char* argv[]) {
172181
} else {
173182
totalPasswords = calculateTotalPasswords(passwordLength, charset);
174183
std::thread generatorThread([&]() {
175-
generatePasswords("", passwordLength, charset, passwordQueue);
184+
if (recursive) {
185+
for (int i = 1; i <= passwordLength; ++i) {
186+
generatePasswords("", i, charset, passwordQueue);
187+
}
188+
} else {
189+
generatePasswords("", passwordLength, charset, passwordQueue);
190+
}
176191
});
177192
generatorThread.detach();
178193
}

0 commit comments

Comments
 (0)