]> git.sesse.net Git - freerainbowtables/blob - Server Applications/rsearchi/HashSet.cpp
initial
[freerainbowtables] / Server Applications / rsearchi / HashSet.cpp
1 /*
2    RainbowCrack - a general propose implementation of Philippe Oechslin's faster time-memory trade-off technique.
3
4    Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
5 */
6
7 #ifdef _WIN32
8         #pragma warning(disable : 4786)
9 #else
10 #define _atoi64 atoll
11 #define stricmp strcasecmp
12 #endif
13
14 #include "HashSet.h"
15 #include <string.h>
16 CHashSet::CHashSet()
17 {
18 }
19
20 CHashSet::~CHashSet()
21 {
22         for(int i = 0; i < m_vIndices.size(); i++)
23         {
24                 delete m_vIndices[i];           
25         }
26 }
27 int CHashSet::GetLookupID(string sHash)
28 {
29         int i;
30         for (i = 0; i < m_vHash.size(); i++)
31         {
32                 if(stricmp(m_vHash[i].c_str(),sHash.c_str()) == 0)
33                 {
34                         return m_vLookupIDs[i];
35                 }
36         }
37
38 }
39 void CHashSet::AddHash(string sHash, uint64 *pIndices, int nLookupID)
40 {
41         if (sHash == "aad3b435b51404ee")
42                 return;
43
44         int i;
45         for (i = 0; i < m_vHash.size(); i++)
46         {
47                 if (m_vHash[i] == sHash)
48                         return;
49         }
50
51         //printf("debug: adding hash %s\n", sHash.c_str());
52
53         m_vHash.push_back(sHash);
54         m_vFound.push_back(false);
55         m_vPlain.push_back("");
56         m_vBinary.push_back("");
57         m_vIndices.push_back(pIndices);
58         m_vLookupIDs.push_back(nLookupID);
59         VECTOR_CHAIN vec;
60         m_vFoundChains.push_back(vec);
61 }
62
63 bool CHashSet::AnyhashLeft()
64 {
65         int i;
66         for (i = 0; i < m_vHash.size(); i++)
67         {
68                 if (!m_vFound[i])
69                         return true;
70         }
71
72         return false;
73 }
74
75 bool CHashSet::AnyHashLeftWithLen(int nLen)
76 {
77         int i;
78         for (i = 0; i < m_vHash.size(); i++)
79         {
80                 if (!m_vFound[i])
81                         if (m_vHash[i].size() == nLen * 2)
82                                 return true;
83         }
84
85         return false;
86 }
87
88 void CHashSet::GetLeftHashWithLen(vector<string>& vHash, vector<uint64 *>& vIndices, int nLen)
89 {
90         vHash.clear();
91         vIndices.clear();
92         int i;
93         for (i = 0; i < m_vHash.size(); i++)
94         {
95                 if (!m_vFound[i])
96                         if (m_vHash[i].size() == nLen * 2)
97                         {
98                                 vHash.push_back(m_vHash[i]);
99                                 vIndices.push_back(m_vIndices[i]);
100                         }
101         }
102 }
103
104 void CHashSet::SetPlain(string sHash, string sPlain, string sBinary)
105 {
106         int i;
107         for (i = 0; i < m_vHash.size(); i++)
108         {
109                 if(stricmp(m_vHash[i].c_str(),sHash.c_str()) == 0)
110                 {
111                         m_vFound[i]    = true;
112                         m_vPlain[i]    = sPlain;
113                         m_vBinary[i]   = sBinary;
114                         return;
115                 }
116         }
117 }
118 // Add a chain to verify (matching endpoint)
119 void CHashSet::AddChain(string sHash, FoundRainbowChain &Chain)
120 {
121         int i;
122         for (i = 0; i < m_vHash.size(); i++)
123         {
124                 if(stricmp(m_vHash[i].c_str(),sHash.c_str()) == 0)
125                 {
126                         m_vFoundChains[i].push_back(Chain);
127                         return;
128                 }
129         }
130 }
131 /*
132 vector<RainbowChain> CHashSet::GetChains(string sHash)
133 {
134         int i;
135         for (i = 0; i < m_vHash.size(); i++)
136         {
137                 if(stricmp(m_vHash[i].c_str(),sHash.c_str()) == 0)
138                 {
139                         return m_vFoundChains[i];
140                 }
141         }
142         VECTOR_CHAIN vec;
143         return vec;
144 }*/
145 bool CHashSet::GetPlain(string sHash, string& sPlain, string& sBinary)
146 {
147         if (stricmp(sHash.c_str(),"aad3b435b51404ee") == 0)
148         {
149                 sPlain  = "";
150                 sBinary = "";
151                 return true;
152         }
153
154         int i;
155         for (i = 0; i < m_vHash.size(); i++)
156         {
157                 if (m_vHash[i] == sHash)
158                 {
159                         if (m_vFound[i])
160                         {
161                                 sPlain  = m_vPlain[i];
162                                 sBinary = m_vBinary[i];
163                                 return true;
164                         }
165                 }
166         }
167
168         return false;
169 }
170
171 int CHashSet::GetStatHashFound()
172 {
173         int nHashFound = 0;
174         int i;
175         for (i = 0; i < m_vHash.size(); i++)
176         {
177                 if (m_vFound[i])
178                         nHashFound++;
179         }
180
181         return nHashFound;
182 }
183
184 int CHashSet::GetStatHashTotal()
185 {
186         return m_vHash.size();
187 }
188
189 void CHashSet::GetFoundChains(map<string, VECTOR_CHAIN> &mHashList)
190 {
191 //      map<string, string> *mHashList = new map<string, string>;
192         for(int i = 0; i < m_vHash.size(); i++)
193         {
194                 mHashList[m_vHash[i]] = m_vFoundChains[i];
195         }
196 //      return mHashList;
197 }