2 Copyright (C) 2008 Steve Thomas <SMT837784@yahoo.com>
4 This file is part of RT Perfecter.
6 RT Perfecter is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 RT Perfecter is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with RT Perfecter. If not, see <http://www.gnu.org/licenses/>.
20 // Current version "RT Perfecter v0.1"
31 #define DIRECTORY_SEPERATOR '\\'
34 #define DIRECTORY_SEPERATOR '/'
37 #define DISPLAY_STATUS_MIN_LOOPS 2000000
42 unsigned int endpt32_1;
43 unsigned int endpt32_2;
44 unsigned short checkpoint;
51 unsigned short checkpoint;
54 void usage(char *runStr);
56 int main(int argc, char **argv)
59 uint64 maxIndex = 0xffffffffffffffff;
61 uint64 maxIndex = 0xffffffffffffffffll;
63 int argi = 1, i, argsUsed = 0;
64 unsigned int maxChainsPerFile = 67108864;
67 if (argc > 3 && argc < 6)
69 for (; argi < argc - 2; argi++)
71 if (strcmp(argv[argi], "-v") == 0 && (argsUsed & 1) == 0)
73 // Enable verbose mode
76 else if (strncmp(argv[argi], "-s=", 3) == 0 && (argsUsed & 2) == 0)
78 // Max file size in MiB
81 for (i = 3; argv[argi][i] >= '0' && argv[argi][i] <= '9'; i++)
83 maxChainsPerFile *= 10;
84 maxChainsPerFile += ((int) argv[argi][i]) - 0x30;
86 if (argv[argi][i] != '\0')
88 printf("Error: Invalid number.\n\n");
92 if (i > 8 || maxChainsPerFile > 65535) // i - 3 > 5
94 printf("Error: Number is to large.\n\n");
98 maxChainsPerFile <<= 16; // maxChainsPerFile *= 1024 * 1024 / 16
100 else if (strncmp(argv[argi], "-i=", 3) == 0 && (argsUsed & 4) == 0)
102 // Maximum index for chains
105 for (i = 3; argv[argi][i] >= '0' && argv[argi][i] <= '9'; i++)
108 maxIndex += ((int) argv[argi][i]) - 0x30;
110 if (argv[argi][i] != '\0')
112 printf("Error: Invalid number.\n\n");
116 if (i > 23) // i - 3 > 20
118 printf("Error: Number is to large.\n\n");
125 printf("Error: Unknown argument.\n\n");
133 if (argc == 1 || argc == 2 && (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-h") == 0))
138 printf("Error: Wrong number of arguments.\n\n");
144 RTChainU chain, prevChain;
145 uint64 uniqueChains = 0;
146 RTRead inRt(argv[argi], maxIndex, argsUsed & 1);
147 RTWrite outRt(argv[argi + 1], maxChainsPerFile);
149 prevChain.c2.endpt32_1 = 0xffffffff;
150 prevChain.c2.endpt32_2 = 0xffffffff;
152 // Set stdin to non-blocking
153 fcntl(0, F_SETFL, fcntl(0, F_GETFL, 0) | O_NDELAY);
157 for (int ret = inRt.readChain(&(chain.c)); ret == 0; ret = inRt.readChain(&(chain.c)))
161 if (loops >= DISPLAY_STATUS_MIN_LOOPS)
164 // Pressing any key will show the status
170 // Pressing enter will show the status
175 } while (ch != (int)'\n' && ch != EOF);
184 // Check the least significate 32 bits first
185 if (chain.c2.endpt32_1 != prevChain.c2.endpt32_1 || chain.c2.endpt32_2 != prevChain.c2.endpt32_2)
187 outRt.writeChain(&(chain.c));
193 printf("Unique Chains: %I64u\nTotal time: %1.2f\n", uniqueChains, (clock() - t) / (double)CLOCKS_PER_SEC);
195 printf("Unique Chains: %llu\nTotal time: %1.2f\n", uniqueChains, (clock() - t) / (double)CLOCKS_PER_SEC);
200 void usage(char *runStr)
202 printf("\n **** RT Perfecter v0.1 ****\n\n");
203 printf("Converts sorted rt files in a directory to a perfect rainbow table. All rt files\n");
204 printf("in the directory must all be from the same rainbow table.\n\n");
205 printf("%s [Options] input-directory output-file-pattern\n\n", runStr);
206 printf("Options:\n");
207 printf(" -i=number\n");
208 printf(" Maximum index for chains.\n\n");
209 printf(" -s=number\n");
210 printf(" Maximum size for output files in MiB [default is 1024, max is 65535].\n\n");
212 printf(" Verbose mode, displays extra info.\n\n");
213 printf("output-file-pattern:\n");
214 printf(" This will be passed into sprintf() with the number of chains in the file and\n");
215 printf(" the current file number starting at 0. This could look like:\n");
216 printf(" 'some-folder%csome-name%%u-%%03u.rt'\n", DIRECTORY_SEPERATOR);
217 printf(" Where '%%u' would be the number of chains in the file and '%%03u' would be the\n");
218 printf(" file number formated like 000, 001, 002, and so on.\n\n");
219 printf("Run-time:\n");
220 printf(" Press [Enter] to display a status message.\n\n");
221 printf("Copyright (c) 2008 Steve Thomas <SMT837784@yahoo.com>\n");
222 printf(" This is free software: you can redistribute it and/or modify it under the\n");
223 printf(" terms of the GNU General Public License as published by the Free Software\n");
224 printf(" Foundation, either version 3 of the License, or (at your option) any later\n");
225 printf(" version. There is NO WARRANTY, to the extent permitted by law.\n");