]> git.sesse.net Git - freerainbowtables/blob - Client Applications/rcracki/HashSet.cpp
actually commit everything
[freerainbowtables] / Client Applications / rcracki / 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 #endif
10
11 #include "HashSet.h"
12
13 CHashSet::CHashSet()
14 {
15 }
16
17 CHashSet::~CHashSet()
18 {
19 }
20
21 void CHashSet::AddHash(string sHash)
22 {
23         if (sHash == "aad3b435b51404ee")
24                 return;
25
26         int i;
27         for (i = 0; i < m_vHash.size(); i++)
28         {
29                 if (m_vHash[i] == sHash)
30                         return;
31         }
32
33         //printf("debug: adding hash %s\n", sHash.c_str());
34
35         m_vHash.push_back(sHash);
36         m_vFound.push_back(false);
37         m_vPlain.push_back("");
38         m_vBinary.push_back("");
39 }
40
41 bool CHashSet::AnyhashLeft()
42 {
43         int i;
44         for (i = 0; i < m_vHash.size(); i++)
45         {
46                 if (!m_vFound[i])
47                         return true;
48         }
49
50         return false;
51 }
52
53 bool CHashSet::AnyHashLeftWithLen(int nLen)
54 {
55         int i;
56         for (i = 0; i < m_vHash.size(); i++)
57         {
58                 if (!m_vFound[i])
59                         if (m_vHash[i].size() == nLen * 2)
60                                 return true;
61         }
62
63         return false;
64 }
65
66 void CHashSet::GetLeftHashWithLen(vector<string>& vHash, int nLen)
67 {
68         vHash.clear();
69
70         int i;
71         for (i = 0; i < m_vHash.size(); i++)
72         {
73                 if (!m_vFound[i])
74                         if (m_vHash[i].size() == nLen * 2)
75                                 vHash.push_back(m_vHash[i]);
76         }
77 }
78
79 void CHashSet::SetPlain(string sHash, string sPlain, string sBinary)
80 {
81         int i;
82         for (i = 0; i < m_vHash.size(); i++)
83         {
84                 if (m_vHash[i] == sHash)
85                 {
86                         m_vFound[i]    = true;
87                         m_vPlain[i]    = sPlain;
88                         m_vBinary[i]   = sBinary;
89                         return;
90                 }
91         }
92 }
93
94 bool CHashSet::GetPlain(string sHash, string& sPlain, string& sBinary)
95 {
96         if (sHash == "aad3b435b51404ee")
97         {
98                 sPlain  = "";
99                 sBinary = "";
100                 return true;
101         }
102
103         int i;
104         for (i = 0; i < m_vHash.size(); i++)
105         {
106                 if (m_vHash[i] == sHash)
107                 {
108                         if (m_vFound[i])
109                         {
110                                 sPlain  = m_vPlain[i];
111                                 sBinary = m_vBinary[i];
112                                 return true;
113                         }
114                 }
115         }
116
117         return false;
118 }
119
120 int CHashSet::GetStatHashFound()
121 {
122         int nHashFound = 0;
123         int i;
124         for (i = 0; i < m_vHash.size(); i++)
125         {
126                 if (m_vFound[i])
127                         nHashFound++;
128         }
129
130         return nHashFound;
131 }
132
133 int CHashSet::GetStatHashTotal()
134 {
135         return m_vHash.size();
136 }