1 // This file is part of BOINC.
2 // http://boinc.berkeley.edu
3 // Copyright (C) 2008 University of California
5 // BOINC is free software; you can redistribute it and/or modify it
6 // under the terms of the GNU Lesser General Public License
7 // as published by the Free Software Foundation,
8 // either version 3 of the License, or (at your option) any later version.
10 // BOINC is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 // See the GNU Lesser General Public License for more details.
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with BOINC. If not, see <http://www.gnu.org/licenses/>.
20 #include "boinc_win.h"
38 #include "boinc_api.h"
41 #include "ChainWalkSet.h"
42 #include "ChainWalkContext.h"
43 typedef unsigned int uint32;
44 //typedef unsigned __int64 uint64;
49 int main(int argc, char **argv) {
51 int c, nchars = 0, retval, n;
53 char output_path[512], chkpt_path[512];
55 retval = boinc_init();
57 fprintf(stderr, "boinc_init returned %d\n", retval);
62 // get size of input file (used to compute fraction done)
64 //file_size(input_path, fsize);
66 // See if there's a valid checkpoint file.
67 // If so seek input file and truncate output file
73 std::cerr << "Not enough parameters";
76 string sHashRoutineName, sCharsetName, sHash;
77 uint32 nRainbowChainCount, nPlainLenMin, nPlainLenMax, nRainbowTableIndex, nRainbowChainLen;
79 sHashRoutineName = argv[1];
80 sCharsetName = argv[2];
81 nPlainLenMin = atoi(argv[3]);
82 nPlainLenMax = atoi(argv[4]);
83 nRainbowTableIndex = atoi(argv[5]);
84 nRainbowChainLen = atoi(argv[6]);
86 //std::cout << "Starting ChainGenerator" << std::endl;
87 // Setup CChainWalkContext
88 //std::cout << "ChainGenerator started." << std::endl;
90 if (!CChainWalkContext::SetHashRoutine(sHashRoutineName))
92 std::cerr << "hash routine " << sHashRoutineName << " not supported" << std::endl;
95 //std::cout << "Hash routine validated" << std::endl;
97 if (!CChainWalkContext::SetPlainCharset(sCharsetName, nPlainLenMin, nPlainLenMax))
99 std::cerr << "charset " << sCharsetName << " not supported" << std::endl;
102 //std::cout << "Plain charset validated" << std::endl;
104 if (!CChainWalkContext::SetRainbowTableIndex(nRainbowTableIndex))
106 std::cerr << "invalid rainbow table index " << nRainbowTableIndex << std::endl;
109 //std::cout << "Rainbowtable index validated" << std::endl;
111 if(sHashRoutineName == "mscache")// || sHashRoutineName == "lmchall" || sHashRoutineName == "halflmchall")
113 // Convert username to unicode
114 const char *szSalt = sSalt.c_str();
115 int salt_length = strlen(szSalt);
116 unsigned char cur_salt[256];
117 for (int i=0; i<salt_length; i++)
119 cur_salt[i*2] = szSalt[i];
120 cur_salt[i*2+1] = 0x00;
122 CChainWalkContext::SetSalt(cur_salt, salt_length*2);
124 else if(sHashRoutineName == "halflmchall")
125 { // The salt is hardcoded into the hash routine
126 // CChainWalkContext::SetSalt((unsigned char*)&salt, 8);
129 else if(sHashRoutineName == "oracle")
131 CChainWalkContext::SetSalt((unsigned char *)sSalt.c_str(), sSalt.length());
134 //std::cout << "Opening chain file" << std::endl;
138 boinc_resolve_filename("result", output_path, sizeof(output_path));
139 FILE *outfile = boinc_fopen(output_path, "wb");
143 std::cerr << "failed to create " << output_path << std::endl;
146 unsigned char TargetHash[255];
148 ParseHash(sHash, TargetHash, nHashLen);
150 CChainWalkContext cwc;
152 bool fNewlyGenerated;
153 uint64* pStartPosIndexE = m_cws.RequestWalk(TargetHash,
163 double nTargetChains = pow((double)nRainbowChainLen - 2, 2) / 2 - (nRainbowChainLen - 2);
166 time_t tStart = time(NULL);
167 for (nPos = nRainbowChainLen - 2; nPos >= 0; nPos--)
169 if(time(NULL) - tStart > 1)
172 double nCurrentChains = pow(((double)nRainbowChainLen - 2 - (double)nPos), 2) / 2 - (nRainbowChainLen - 2);
173 double fResult = ((double)((double)(nCurrentChains) / nTargetChains));
176 boinc_fraction_done(fResult);
179 cwc.SetHash(TargetHash);
180 cwc.HashToIndex(nPos);
182 for (i = nPos + 1; i <= nRainbowChainLen - 2; i++)
188 uint64 index = cwc.GetIndex();
189 if(fwrite(&index, 8, 1, outfile) != 1)
191 fprintf(stderr, "unable to write to outfile");
194 //nChainWalkStep += nRainbowChainLen - 2 - nPos;
197 double nCurrentChains = pow(((double)nRainbowChainLen - 2 - (double)nPos), 2) / 2 - (nRainbowChainLen - 2);
198 double fResult = ((double)((double)(nCurrentChains) / nTargetChains));
199 boinc_fraction_done(fResult);
205 // main loop - read characters, convert to UC, write
208 boinc_fraction_done(1);
213 int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR Args, int WinMode) {
218 command_line = GetCommandLine();
219 argc = parse_command_line( command_line, argv );
220 return main(argc, argv);
224 const char *BOINC_RCSID_33ac47a071 = "$Id: upper_case.C 12135 2007-02-21 20:04:14Z davea $";