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)
29 #include <sys/sysinfo.h>
32 //////////////////////////////////////////////////////////////////////
34 unsigned int GetFileLen(FILE* file)
36 unsigned int pos = ftell(file);
37 fseek(file, 0, SEEK_END);
38 unsigned int len = ftell(file);
39 fseek(file, pos, SEEK_SET);
44 string TrimString(string s)
48 if (s[0] == ' ' || s[0] == '\t')
56 if (s[s.size() - 1] == ' ' || s[s.size() - 1] == '\t')
57 s = s.substr(0, s.size() - 1);
64 bool GetHybridCharsets(string sCharset, vector<tCharset>& vCharset)
66 // Example: hybrid(mixalpha-numeric-all-space#1-6,numeric#1-4)
67 if(sCharset.substr(0, 6) != "hybrid") // Not hybrid charset
69 size_t nEnd = sCharset.rfind(')');
70 size_t nStart = sCharset.rfind('(');
71 string sChar = sCharset.substr(nStart + 1, nEnd - nStart - 1);
72 vector<string> vParts;
73 SeperateString(sChar, ",", vParts);
74 for(int i = 0; i < vParts.size(); i++)
77 vector<string> vParts2;
78 SeperateString(vParts[i], "#", vParts2);
79 stCharset.sName = vParts2[0];
80 vector<string> vParts3;
81 SeperateString(vParts2[1], "-", vParts3);
82 stCharset.nPlainLenMin = atoi(vParts3[0].c_str());
83 stCharset.nPlainLenMax = atoi(vParts3[1].c_str());
84 vCharset.push_back(stCharset);
88 bool ReadLinesFromFile(string sPathName, vector<string>& vLine)
91 FILE *file = fopen(sPathName.c_str(), "rb");
94 unsigned int len = GetFileLen(file);
95 char* data = new char[len + 1];
96 fread(data, 1, len, file);
98 string content = data;
103 for (i = 0; i < content.size(); i++)
105 if (content[i] == '\r')
110 while ((n = content.find("\n", 0)) != -1)
112 string line = content.substr(0, n);
113 line = TrimString(line);
115 vLine.push_back(line);
116 content = content.substr(n + 1);
127 bool SeperateString(string s, string sSeperator, vector<string>& vPart)
132 for (i = 0; i < sSeperator.size(); i++)
134 int n = s.find(sSeperator[i]);
137 vPart.push_back(s.substr(0, n));
148 string uint64tostr(uint64 n)
153 sprintf(str, "%I64u", n);
155 sprintf(str, "%llu", n);
161 string uint64tohexstr(uint64 n)
166 sprintf(str, "%016I64x", n);
168 sprintf(str, "%016llx", n);
174 string HexToStr(const unsigned char* pData, int nLen)
178 for (i = 0; i < nLen; i++)
181 sprintf(szByte, "%02x", pData[i]);
188 unsigned int GetAvailPhysMemorySize()
192 GlobalMemoryStatus(&ms);
193 return ms.dwAvailPhys;
196 sysinfo(&info); // This function is Linux-specific
201 void ParseHash(string sHash, unsigned char* pHash, int& nHashLen)
204 for (i = 0; i < sHash.size() / 2; i++)
206 string sSub = sHash.substr(i * 2, 2);
208 sscanf(sSub.c_str(), "%02x", &nValue);
209 pHash[i] = (unsigned char)nValue;
212 nHashLen = sHash.size() / 2;
217 printf("RainbowCrack (improved) 2.0 - Making a Faster Cryptanalytic Time-Memory Trade-Off\n");
218 printf("by Martin Westergaard <martinwj2005@gmail.com>\n");
219 printf("http://www.freerainbowtables.com/\n");
220 printf("original code by Zhu Shuanglei <shuanglei@hotmail.com>\n");
221 printf("http://www.antsight.com/zsl/rainbowcrack/\n\n");