2 RainbowCrack - a general propose implementation of Philippe Oechslin's faster time-memory trade-off technique.
4 Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
8 #pragma warning(disable : 4786)
13 #include "boinc_win.h"
28 #include "boinc_api.h"
35 #include <sys/sysinfo.h>
38 //////////////////////////////////////////////////////////////////////
40 unsigned int GetFileLen(FILE* file)
42 unsigned int pos = ftell(file);
43 fseek(file, 0, SEEK_END);
44 unsigned int len = ftell(file);
45 fseek(file, pos, SEEK_SET);
50 string TrimString(string s)
54 if (s[0] == ' ' || s[0] == '\t')
62 if (s[s.size() - 1] == ' ' || s[s.size() - 1] == '\t')
63 s = s.substr(0, s.size() - 1);
70 bool GetHybridCharsets(string sCharset, vector<tCharset>& vCharset)
72 // Example: hybrid(mixalpha-numeric-all-space#1-6,numeric#1-4)
73 if(sCharset.substr(0, 6) != "hybrid") // Not hybrid charset
75 size_t nEnd = sCharset.rfind(')');
76 size_t nStart = sCharset.rfind('(');
77 string sChar = sCharset.substr(nStart + 1, nEnd - nStart - 1);
78 vector<string> vParts;
79 SeperateString(sChar, ",", vParts);
80 for(int i = 0; i < vParts.size(); i++)
83 vector<string> vParts2;
84 SeperateString(vParts[i], "#", vParts2);
85 stCharset.sName = vParts2[0];
86 vector<string> vParts3;
87 SeperateString(vParts2[1], "-", vParts3);
88 stCharset.nPlainLenMin = atoi(vParts3[0].c_str());
89 stCharset.nPlainLenMax = atoi(vParts3[1].c_str());
90 vCharset.push_back(stCharset);
95 bool boinc_ReadLinesFromFile(string sPathName, vector<string>& vLine)
99 boinc_resolve_filename(sPathName.c_str(), input_path, sizeof(input_path));
100 FILE *file = boinc_fopen(input_path, "rb");
103 "Couldn't find input file, resolved name %s.\n", input_path
109 unsigned int len = GetFileLen(file);
110 char* data = new char[len + 1];
111 fread(data, 1, len, file);
113 string content = data;
118 for (i = 0; i < content.size(); i++)
120 if (content[i] == '\r')
125 while ((n = content.find("\n", 0)) != -1)
127 string line = content.substr(0, n);
128 line = TrimString(line);
130 vLine.push_back(line);
131 content = content.substr(n + 1);
142 bool ReadLinesFromFile(string sPathName, vector<string>& vLine)
145 FILE *file = fopen(sPathName.c_str(), "rb");
148 unsigned int len = GetFileLen(file);
149 char* data = new char[len + 1];
150 fread(data, 1, len, file);
152 string content = data;
157 for (i = 0; i < content.size(); i++)
159 if (content[i] == '\r')
164 while ((n = content.find("\n", 0)) != -1)
166 string line = content.substr(0, n);
167 line = TrimString(line);
169 vLine.push_back(line);
170 content = content.substr(n + 1);
182 bool SeperateString(string s, string sSeperator, vector<string>& vPart)
187 for (i = 0; i < sSeperator.size(); i++)
189 int n = s.find(sSeperator[i]);
192 vPart.push_back(s.substr(0, n));
203 string uint64tostr(uint64 n)
208 sprintf(str, "%I64u", n);
210 sprintf(str, "%llu", n);
216 string uint64tohexstr(uint64 n)
221 sprintf(str, "%016I64x", n);
223 sprintf(str, "%016llx", n);
229 string HexToStr(const unsigned char* pData, int nLen)
233 for (i = 0; i < nLen; i++)
236 sprintf(szByte, "%02x", pData[i]);
243 unsigned int GetAvailPhysMemorySize()
247 GlobalMemoryStatus(&ms);
248 return ms.dwAvailPhys;
251 sysinfo(&info); // This function is Linux-specific
256 void ParseHash(string sHash, unsigned char* pHash, int& nHashLen)
259 for (i = 0; i < sHash.size() / 2; i++)
261 string sSub = sHash.substr(i * 2, 2);
263 sscanf(sSub.c_str(), "%02x", &nValue);
264 pHash[i] = (unsigned char)nValue;
267 nHashLen = sHash.size() / 2;
272 printf("RainbowCrack (improved) 2.0 - Making a Faster Cryptanalytic Time-Memory Trade-Off\n");
273 printf("by Martin Westergaard <martinwj2005@gmail.com>\n");
274 printf("http://www.freerainbowtables.com/\n");
275 printf("original code by Zhu Shuanglei <shuanglei@hotmail.com>\n");
276 printf("http://www.antsight.com/zsl/rainbowcrack/\n\n");