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)
12 #include "boinc_win.h"
25 #include "boinc_api.h"
31 #include <sys/sysinfo.h>
34 //////////////////////////////////////////////////////////////////////
36 unsigned int GetFileLen(FILE* file)
38 unsigned int pos = ftell(file);
39 fseek(file, 0, SEEK_END);
40 unsigned int len = ftell(file);
41 fseek(file, pos, SEEK_SET);
46 string TrimString(string s)
50 if (s[0] == ' ' || s[0] == '\t')
58 if (s[s.size() - 1] == ' ' || s[s.size() - 1] == '\t')
59 s = s.substr(0, s.size() - 1);
66 bool GetHybridCharsets(string sCharset, vector<tCharset>& vCharset)
68 // Example: hybrid(mixalpha-numeric-all-space#1-6,numeric#1-4)
69 if(sCharset.substr(0, 6) != "hybrid") // Not hybrid charset
71 size_t nEnd = sCharset.rfind(')');
72 size_t nStart = sCharset.rfind('(');
73 string sChar = sCharset.substr(nStart + 1, nEnd - nStart - 1);
74 vector<string> vParts;
75 SeperateString(sChar, ",", vParts);
76 for(int i = 0; i < vParts.size(); i++)
79 vector<string> vParts2;
80 SeperateString(vParts[i], "#", vParts2);
81 stCharset.sName = vParts2[0];
82 vector<string> vParts3;
83 SeperateString(vParts2[1], "-", vParts3);
84 stCharset.nPlainLenMin = atoi(vParts3[0].c_str());
85 stCharset.nPlainLenMax = atoi(vParts3[1].c_str());
86 vCharset.push_back(stCharset);
90 bool ReadLinesFromFile(string sPathName, vector<string>& vLine)
93 // open the input file (resolve logical name first)
95 boinc_resolve_filename(INPUT_FILENAME, input_path, sizeof(input_path));
96 FILE *file = boinc_fopen(input_path, "rb");
99 "Couldn't find input file, resolved name %s.\n", input_path
107 unsigned int len = GetFileLen(file);
108 char* data = new char[len + 1];
109 fread(data, 1, len, file);
111 string content = data;
116 for (i = 0; i < content.size(); i++)
118 if (content[i] == '\r')
123 while ((n = content.find("\n", 0)) != -1)
125 string line = content.substr(0, n);
126 line = TrimString(line);
128 vLine.push_back(line);
129 content = content.substr(n + 1);
140 bool SeperateString(string s, string sSeperator, vector<string>& vPart)
145 for (i = 0; i < sSeperator.size(); i++)
147 int n = s.find(sSeperator[i]);
150 vPart.push_back(s.substr(0, n));
161 string uint64tostr(uint64 n)
166 sprintf_s(str, sizeof(str), "%I64u", n);
168 sprintf(str, "%llu", n);
174 string uint64tohexstr(uint64 n)
179 sprintf_s(str, sizeof(str), "%016I64x", n);
181 sprintf(str, "%016llx", n);
187 string HexToStr(const unsigned char* pData, int nLen)
191 for (i = 0; i < nLen; i++)
195 sprintf_s(szByte, sizeof(szByte), "%02x", pData[i]);
197 sprintf(szByte, "%02x", pData[i]);
206 unsigned int GetAvailPhysMemorySize()
210 GlobalMemoryStatus(&ms);
211 return ms.dwAvailPhys;
214 sysinfo(&info); // This function is Linux-specific
219 void ParseHash(string sHash, unsigned char* pHash, int& nHashLen)
222 for (i = 0; i < sHash.size() / 2; i++)
224 string sSub = sHash.substr(i * 2, 2);
227 sscanf_s(sSub.c_str(), "%02x", &nValue);
229 sscanf(sSub.c_str(), "%02x", &nValue);
231 pHash[i] = (unsigned char)nValue;
234 nHashLen = sHash.size() / 2;
239 printf("RainbowCrack 1.2 - Making a Faster Cryptanalytic Time-Memory Trade-Off\n");
240 printf("by Zhu Shuanglei <shuanglei@hotmail.com>\n");
241 printf("http://www.antsight.com/zsl/rainbowcrack/\n\n");