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)
15 #include <sys/sysinfo.h>
18 //////////////////////////////////////////////////////////////////////
20 unsigned int GetFileLen(FILE* file)
22 unsigned int pos = ftell(file);
23 fseek(file, 0, SEEK_END);
24 unsigned int len = ftell(file);
25 fseek(file, pos, SEEK_SET);
29 string TrimString(string s)
33 if (s[0] == ' ' || s[0] == '\t')
41 if (s[s.size() - 1] == ' ' || s[s.size() - 1] == '\t')
42 s = s.substr(0, s.size() - 1);
50 bool ReadLinesFromFile(string sPathName, vector<string>& vLine)
54 FILE* file = fopen(sPathName.c_str(), "rb");
57 unsigned int len = GetFileLen(file);
58 char* data = new char[len + 1];
59 fread(data, 1, len, file);
61 string content = data;
66 for (i = 0; i < content.size(); i++)
68 if (content[i] == '\r')
73 while ((n = content.find("\n", 0)) != -1)
75 string line = content.substr(0, n);
76 line = TrimString(line);
78 vLine.push_back(line);
79 content = content.substr(n + 1);
90 bool SeperateString(string s, string sSeperator, vector<string>& vPart)
95 for (i = 0; i < sSeperator.size(); i++)
97 int n = s.find(sSeperator[i]);
100 vPart.push_back(s.substr(0, n));
111 string uint64tostr(uint64 n)
116 sprintf(str, "%I64u", n);
118 sprintf(str, "%llu", n);
124 string uint64tohexstr(uint64 n)
129 sprintf(str, "%016I64x", n);
131 sprintf(str, "%016llx", n);
137 string HexToStr(const unsigned char* pData, int nLen)
141 for (i = 0; i < nLen; i++)
144 sprintf(szByte, "%02x", pData[i]);
151 unsigned int GetAvailPhysMemorySize()
156 GlobalMemoryStatus(&ms);
157 return ms.dwAvailPhys;
160 sysinfo(&info); // This function is Linux-specific
162 return 200 * 1024 * 1024;
163 // return info.freeram;
167 void ParseHash(string sHash, unsigned char* pHash, int& nHashLen)
170 for (i = 0; i < sHash.size() / 2; i++)
172 string sSub = sHash.substr(i * 2, 2);
174 sscanf(sSub.c_str(), "%02x", &nValue);
175 pHash[i] = (unsigned char)nValue;
178 nHashLen = sHash.size() / 2;
183 printf("RainbowCrack 1.2 - Making a Faster Cryptanalytic Time-Memory Trade-Off\n");
184 printf("by Zhu Shuanglei <shuanglei@hotmail.com>\n");
185 printf("http://www.antsight.com/zsl/rainbowcrack/\n\n");
188 bool GetHybridCharsets(string sCharset, vector<tCharset>& vCharset)
190 // Example: hybrid(mixalpha-numeric-all-space#1-6,numeric#1-4)
191 if(sCharset.substr(0, 6) != "hybrid") // Not hybrid charset
193 size_t nEnd = sCharset.rfind(')');
194 size_t nStart = sCharset.rfind('(');
195 string sChar = sCharset.substr(nStart + 1, nEnd - nStart - 1);
196 vector<string> vParts;
197 SeperateString(sChar, ",", vParts);
198 for(int i = 0; i < vParts.size(); i++)
201 vector<string> vParts2;
202 SeperateString(vParts[i], "#", vParts2);
203 stCharset.sName = vParts2[0];
204 vector<string> vParts3;
205 SeperateString(vParts2[1], "-", vParts3);
206 stCharset.nPlainLenMin = atoi(vParts3[0].c_str());
207 stCharset.nPlainLenMax = atoi(vParts3[1].c_str());
208 vCharset.push_back(stCharset);