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/>.
18 // This program serves as both
19 // - An example BOINC application, illustrating the use of the BOINC API
20 // - A program for testing various features of BOINC
22 // NOTE: this file exists as both
23 // boinc/apps/upper_case.C
25 // boinc_samples/example_app/uc2.C
26 // If you update one, please update the other!
28 // The program converts a mixed-case file to upper case:
29 // read "in", convert to upper case, write to "out"
31 // command line options
32 // -run_slow: sleep 1 second after each character
33 // -cpu_time N: use about N CPU seconds after copying files
34 // -early_exit: exit(10) after 30 chars
35 // -early_crash: crash after 30 chars
56 #include "ChainWalkContext.h"
57 typedef unsigned int uint32;
58 //typedef unsigned __int64 uint64;
64 bool early_exit = false;
65 bool early_crash = false;
66 bool early_sleep = false;
67 double cpu_time = 20, comp_result;
69 int main(int argc, char **argv) {
76 fprintf(stderr, "Not enough parameters");
79 string sHashRoutineName, sCharsetName, sSalt, sCheckPoints;
80 uint32 nRainbowChainCount, nPlainLenMin, nPlainLenMax, nRainbowTableIndex, nRainbowChainLen;
82 sHashRoutineName = argv[1];
83 sCharsetName = argv[2];
84 nPlainLenMin = atoi(argv[3]);
85 nPlainLenMax = atoi(argv[4]);
86 nRainbowTableIndex = atoi(argv[5]);
87 nRainbowChainLen = atoi(argv[6]);
88 nRainbowChainCount = atoi(argv[7]);
91 nChainStart = _atoi64(argv[8]);
94 nChainStart = atoll(argv[8]);
96 sCheckPoints = argv[9];
97 vector<int> vCPPositions;
98 char *cp = strtok((char *)sCheckPoints.c_str(), ",");
101 vCPPositions.push_back(atoi(cp));
102 cp = strtok(NULL, ",");
108 //std::cout << "Starting ChainGenerator" << std::endl;
109 // Setup CChainWalkContext
110 //std::cout << "ChainGenerator started." << std::endl;
112 if (!CChainWalkContext::SetHashRoutine(sHashRoutineName))
114 fprintf(stderr, "hash routine %s not supported\n", sHashRoutineName.c_str());
117 //std::cout << "Hash routine validated" << std::endl;
119 if (!CChainWalkContext::SetPlainCharset(sCharsetName, nPlainLenMin, nPlainLenMax))
121 std::cerr << "charset " << sCharsetName << " not supported" << std::endl;
124 //std::cout << "Plain charset validated" << std::endl;
126 if (!CChainWalkContext::SetRainbowTableIndex(nRainbowTableIndex))
128 std::cerr << "invalid rainbow table index " << nRainbowTableIndex << std::endl;
131 //std::cout << "Rainbowtable index validated" << std::endl;
133 if(sHashRoutineName == "mscache")// || sHashRoutineName == "lmchall" || sHashRoutineName == "halflmchall")
135 // Convert username to unicode
136 const char *szSalt = sSalt.c_str();
137 int salt_length = strlen(szSalt);
138 unsigned char cur_salt[256];
139 for (int i=0; i<salt_length; i++)
141 cur_salt[i*2] = szSalt[i];
142 cur_salt[i*2+1] = 0x00;
144 CChainWalkContext::SetSalt(cur_salt, salt_length*2);
146 else if(sHashRoutineName == "halflmchall")
147 { // The salt is hardcoded into the hash routine
148 // CChainWalkContext::SetSalt((unsigned char*)&salt, 8);
150 else if(sHashRoutineName == "oracle")
152 CChainWalkContext::SetSalt((unsigned char *)sSalt.c_str(), sSalt.length());
154 //std::cout << "Opening chain file" << std::endl;
158 // Check existing chains
160 CChainWalkContext cwc;
162 time_t tStart = time(NULL);
163 // std::cout << "Starting to generate chains" << std::endl;
164 for(int nCurrentCalculatedChains = 0; nCurrentCalculatedChains < nRainbowChainCount; nCurrentCalculatedChains++)
167 unsigned short checkpoint = 0;
168 fd = (double)nCurrentCalculatedChains / (double)nRainbowChainCount;
169 cwc.SetIndex(nChainStart++); // use a given index now!
170 nIndex[0] = cwc.GetIndex();
172 for (int nPos = 0; nPos < nRainbowChainLen - 1; nPos++)
174 // std::cout << "IndexToPlain()" << std::endl;
176 // std::cout << "PlainToHash()" << std::endl;
178 // std::cout << "HashToIndex()" << std::endl;
179 cwc.HashToIndex(nPos);
180 if(cpcheck < vCPPositions.size() && nPos == vCPPositions[cpcheck])
183 checkpoint |= (1 << cpcheck) & (unsigned short)cwc.GetIndex() << cpcheck;
187 //std::cout << "GetIndex()" << std::endl;
189 nIndex[1] = cwc.GetIndex();
190 // Write chain to disk
192 //std::cout << "Generation completed" << std::endl;
195 // main loop - read characters, convert to UC, write