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)
16 #include <sys/sysinfo.h>
19 //////////////////////////////////////////////////////////////////////
21 unsigned int GetFileLen(FILE* file)
23 unsigned int pos = ftell(file);
24 fseek(file, 0, SEEK_END);
25 unsigned int len = ftell(file);
26 fseek(file, pos, SEEK_SET);
31 string TrimString(string s)
35 if (s[0] == ' ' || s[0] == '\t')
43 if (s[s.size() - 1] == ' ' || s[s.size() - 1] == '\t')
44 s = s.substr(0, s.size() - 1);
51 bool GetHybridCharsets(string sCharset, vector<tCharset>& vCharset)
53 // Example: hybrid(mixalpha-numeric-all-space#1-6,numeric#1-4)
54 if(sCharset.substr(0, 6) != "hybrid") // Not hybrid charset
56 size_t nEnd = sCharset.rfind(')');
57 size_t nStart = sCharset.rfind('(');
58 string sChar = sCharset.substr(nStart + 1, nEnd - nStart - 1);
59 vector<string> vParts;
60 SeperateString(sChar, ",", vParts);
61 for(int i = 0; i < vParts.size(); i++)
64 vector<string> vParts2;
65 SeperateString(vParts[i], "#", vParts2);
66 stCharset.sName = vParts2[0];
67 vector<string> vParts3;
68 SeperateString(vParts2[1], "-", vParts3);
69 stCharset.nPlainLenMin = atoi(vParts3[0].c_str());
70 stCharset.nPlainLenMax = atoi(vParts3[1].c_str());
71 vCharset.push_back(stCharset);
75 bool ReadLinesFromFile(string sPathName, vector<string>& vLine)
79 FILE* file = fopen(sPathName.c_str(), "rb");
82 unsigned int len = GetFileLen(file);
83 char* data = new char[len + 1];
84 fread(data, 1, len, file);
86 string content = data;
91 for (i = 0; i < content.size(); i++)
93 if (content[i] == '\r')
98 while ((n = content.find("\n", 0)) != -1)
100 string line = content.substr(0, n);
101 line = TrimString(line);
103 vLine.push_back(line);
104 content = content.substr(n + 1);
115 bool SeperateString(string s, string sSeperator, vector<string>& vPart)
120 for (i = 0; i < sSeperator.size(); i++)
122 int n = s.find(sSeperator[i]);
125 vPart.push_back(s.substr(0, n));
136 string uint64tostr(uint64 n)
141 sprintf(str, "%I64u", n);
143 sprintf(str, "%llu", n);
149 string uint64tohexstr(uint64 n)
154 sprintf(str, "%016I64x", n);
156 sprintf(str, "%016llx", n);
162 string HexToStr(const unsigned char* pData, int nLen)
166 for (i = 0; i < nLen; i++)
169 sprintf(szByte, "%02x", pData[i]);
176 unsigned int GetAvailPhysMemorySize()
180 GlobalMemoryStatus(&ms);
181 return ms.dwAvailPhys;
184 sysinfo(&info); // This function is Linux-specific
189 void ParseHash(string sHash, unsigned char* pHash, int& nHashLen)
192 for (i = 0; i < sHash.size() / 2; i++)
194 string sSub = sHash.substr(i * 2, 2);
196 sscanf(sSub.c_str(), "%02x", &nValue);
197 pHash[i] = (unsigned char)nValue;
200 nHashLen = sHash.size() / 2;
205 printf("RainbowCrack (improved) 2.0 - Making a Faster Cryptanalytic Time-Memory Trade-Off\n");
206 printf("by Martin Westergaard <martinwj2005@gmail.com>\n");
207 printf("http://www.freerainbowtables.com/\n");
208 printf("original code by Zhu Shuanglei <shuanglei@hotmail.com>\n");
209 printf("http://www.antsight.com/zsl/rainbowcrack/\n\n");