]> git.sesse.net Git - freerainbowtables/blob - Client Applications/rcracki_mt/HashSet.cpp
test
[freerainbowtables] / Client Applications / rcracki_mt / HashSet.cpp
1 /*
2  * rcracki_mt is a multithreaded implementation and fork of the original 
3  * RainbowCrack
4  *
5  * Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
6  * Copyright Martin Westergaard Jørgensen <martinwj2005@gmail.com>
7  * Copyright 2009, 2010 Daniël Niggebrugge <niggebrugge@fox-it.com>
8  * Copyright 2009, 2010 James Nobis <frt@quelrod.net>
9  *
10  * This file is part of rcracki_mt.
11  *
12  * rcracki_mt is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation, either version 2 of the License, or
15  * (at your option) any later version.
16  *
17  * rcracki_mt is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with rcracki_mt.  If not, see <http://www.gnu.org/licenses/>.
24  */
25
26 #if defined(_WIN32) && !defined(__GNUC__)
27         #pragma warning(disable : 4786 4267 4018)
28 #endif
29
30 #include "HashSet.h"
31
32 CHashSet::CHashSet()
33 {
34 }
35
36 CHashSet::~CHashSet()
37 {
38 }
39
40 void CHashSet::AddHash(string sHash)
41 {
42         if (sHash == "aad3b435b51404ee")
43                 return;
44
45         UINT4 i;
46         for (i = 0; i < m_vHash.size(); i++)
47         {
48                 if (m_vHash[i] == sHash)
49                         return;
50         }
51
52         //printf("debug: adding hash %s\n", sHash.c_str());
53
54         m_vHash.push_back(sHash);
55         m_vFound.push_back(false);
56         m_vPlain.push_back("");
57         m_vBinary.push_back("");
58 }
59
60 string CHashSet::GetHashInfo(int i)
61 {
62         string found;
63         if (m_vFound[i])
64                 found = "1";
65         else
66                 found = "0";
67
68         string buffer = m_vHash[i] + ":" + found + ":" + m_vPlain[i] + ":" + m_vBinary[i];
69
70         return buffer;
71 }
72
73 bool CHashSet::AnyhashLeft()
74 {
75         UINT4 i;
76         for (i = 0; i < m_vHash.size(); i++)
77         {
78                 if (!m_vFound[i])
79                         return true;
80         }
81
82         return false;
83 }
84
85 bool CHashSet::AnyHashLeftWithLen(int nLen)
86 {
87         UINT4 i;
88         for (i = 0; i < m_vHash.size(); i++)
89         {
90                 if (!m_vFound[i])
91                         if (m_vHash[i].size() == (unsigned long)nLen * 2)
92                                 return true;
93         }
94
95         return false;
96 }
97
98 void CHashSet::GetLeftHashWithLen(vector<string>& vHash, int nLen)
99 {
100         vHash.clear();
101
102         UINT4 i;
103         for (i = 0; i < m_vHash.size(); i++)
104         {
105                 if (!m_vFound[i])
106                         if (m_vHash[i].size() == (unsigned long)nLen * 2)
107                                 vHash.push_back(m_vHash[i]);
108         }
109 }
110
111 void CHashSet::AddHashInfo(string sHash, bool found, string sPlain, string sBinary)
112 {
113         UINT4 i;
114         for (i = 0; i < m_vHash.size(); i++)
115         {
116                 if (m_vHash[i] == sHash)
117                         return;
118         }
119
120         m_vHash.push_back(sHash);
121         m_vFound.push_back(found);
122         m_vPlain.push_back(sPlain);
123         m_vBinary.push_back(sBinary);
124 }
125
126 void CHashSet::SetPlain(string sHash, string sPlain, string sBinary)
127 {
128         UINT4 i;
129         for (i = 0; i < m_vHash.size(); i++)
130         {
131                 if (m_vHash[i] == sHash)
132                 {
133                         m_vFound[i]    = true;
134                         m_vPlain[i]    = sPlain;
135                         m_vBinary[i]   = sBinary;
136                         return;
137                 }
138         }
139 }
140
141 bool CHashSet::GetPlain(string sHash, string& sPlain, string& sBinary)
142 {
143         if (sHash == "aad3b435b51404ee")
144         {
145                 sPlain  = "";
146                 sBinary = "";
147                 return true;
148         }
149
150         UINT4 i;
151         for (i = 0; i < m_vHash.size(); i++)
152         {
153                 if (m_vHash[i] == sHash)
154                 {
155                         if (m_vFound[i])
156                         {
157                                 sPlain  = m_vPlain[i];
158                                 sBinary = m_vBinary[i];
159                                 return true;
160                         }
161                 }
162         }
163
164         return false;
165 }
166
167 int CHashSet::GetStatHashFound()
168 {
169         int nHashFound = 0;
170         UINT4 i;
171         for (i = 0; i < m_vHash.size(); i++)
172         {
173                 if (m_vFound[i])
174                         nHashFound++;
175         }
176
177         return nHashFound;
178 }
179
180 int CHashSet::GetStatHashTotal()
181 {
182         return (int) m_vHash.size();
183 }