Debian Codegraph @

src/gui/graphdialog.cpp

raw symbols SCIP
1 /*
2 *
3 * Ophcrack is a Lanmanager/NTLM hash cracker based on the faster time-memory
4 * trade-off using rainbow tables.
5 *
6 * Created with the help of: Maxime Mueller, Luca Wullschleger, Claude
7 * Hochreutiner, Andreas Huber and Etienne Dysli.
8 *
9 * Copyright (c) 2009 Philippe Oechslin, Cedric Tissieres, Bertrand Mesot
10 *
11 * Ophcrack is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * Ophcrack is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with Ophcrack; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 *
25 * This program is released under the GPL with the additional exemption
26 * that compiling, linking, and/or using OpenSSL is allowed.
27 *
28 *
29 *
30 *
31 */
32 #include <math.h>
33 #include <QtCharts/QBarSeries>
34 #include "graphdialog.h"
35 //---------------------------------------------------------------------------
36 GraphDialog::GraphDialog(QWidget *parent) : QDialog(parent) {
37 setupUi(this);
38
39 lengthHistogram = 0;
40 categoryHistogram = 0;
41 timeCurve = 0;
42 }
43 //---------------------------------------------------------------------------
44 void GraphDialog::plot(ophstat_t *stats, int crack_time) {
45
46 this->plotHistoLength(stats->length, lengthChartView);
47 this->plotHistoCategory(stats->category, categoryChartView);
48 this->plotCurve(stats->time, crack_time, timeChartView);
49 }
50 //---------------------------------------------------------------------------
51 void GraphDialog::initBarGraph(const int numValues, QChart *chart, QBarSet *set, QValueAxis *axisX, QValueAxis *axisY, QString title, const QColor color) {
52
53 int i;
54 uint32_t max = 1;
55
56 set->setColor(color);
57 for ( i = 0; i < numValues; i++ )
58 set->append(0);
59 QBarSeries *series = new QBarSeries();
60 series->setBarWidth(0.9);
61 series->append(set);
62
63 chart->addSeries(series);
64
65 axisX->setRange(0, numValues-1);
66 axisX->setLabelFormat("%i");
67 axisX->setTickCount(numValues);
68 chart->setAxisX(axisX, series);
69
70 axisY->setRange(0, max);
71 axisY->setLabelFormat("%i");
72 axisY->setTickCount(2);
73 chart->setAxisY(axisY, series);
74
75 chart->legend()->setVisible(false);
76 chart->setTitle(title);
77 }
78
79 //---------------------------------------------------------------------------
80 void GraphDialog::plotHistoLength(uint32_t *val, QChartView *view) {
81
82 int i;
83 const int numValues = 16;
84 uint32_t max = 1;
85 static const QColor green = QColor(143, 196, 66);
86
87 if (lengthHistogram == 0) {
88 lengthHistogram = new QChart();
89 lengthSet = new QBarSet("");
90 lengthAxisX = new QValueAxis();
91 lengthAxisY = new QValueAxis();
92 initBarGraph(numValues, lengthHistogram, lengthSet, lengthAxisX, lengthAxisY, "Distribution of length", green);
93 view->setChart(lengthHistogram);
94 }
95
96 for ( i = 0; i < numValues; i++ ) {
97 lengthSet->replace(i, val[i]);
98 if (val[i] > max)
99 max = val[i];
100 }
101 lengthAxisY->setRange(0, max);
102 lengthAxisY->setTickCount((max > 5) ? 5 : max+1);
103 lengthAxisY->applyNiceNumbers();
104
105 }
106 //---------------------------------------------------------------------------
107 void GraphDialog::plotHistoCategory(uint32_t *val, QChartView *view) {
108
109 int i;
110 const int numValues = 6;
111 uint32_t max = 1;
112 static const QColor red = QColor(169, 52, 52);
113
114 if (categoryHistogram == 0) {
115 categoryHistogram = new QChart();
116 categorySet = new QBarSet("");
117 categoryAxisX = new QValueAxis();
118 categoryAxisY = new QValueAxis();
119 initBarGraph(numValues, categoryHistogram, categorySet, categoryAxisX, categoryAxisY, "Category of passwords", red);
120 view->setChart(categoryHistogram);
121 }
122
123 for ( i = 0; i < numValues; i++ ) {
124 categorySet->replace(i, val[i]);
125 if (val[i] > max)
126 max = val[i];
127 }
128 categoryAxisY->setRange(0, max);
129 categoryAxisY->setTickCount((max > 5) ? 5 : max+1);
130 categoryAxisY->applyNiceNumbers();
131
132 }
133 //---------------------------------------------------------------------------
134 void GraphDialog::plotCurve(list_t *list, int crack_time, QChartView *view) {
135 int i;
136 list_nd_t *lnd;
137 int hsh_time;
138 int numValues = (128 > list->size) ? 128 : list->size;
139 QVector<float> tempX(QVector<float>(numValues, 0.0));
140 QVector<float> tempY(QVector<float>(numValues, 0.0));
141
142 if (timeCurve == 0) {
143 timeVector = new QVector<QPointF>();
144 timeVector->append(QPointF(0.0, 0.0));
145 timeCurve = new QChart();
146 timeSeries = new QLineSeries();
147 timeAxisX = new QValueAxis();
148 timeAxisY = new QValueAxis();
149
150 timeCurve->addSeries(timeSeries);
151
152 timeAxisX->setRange(0.0, crack_time);
153 timeAxisX->setLabelFormat("%i");
154 timeCurve->setAxisX(timeAxisX, timeSeries);
155
156 timeAxisY->setRange(0.0, 1.0);
157 timeAxisY->setLabelFormat("%i");
158 timeCurve->setAxisY(timeAxisY, timeSeries);
159
160 timeCurve->legend()->setVisible(false);
161 timeCurve->setTitle("Cracking time");
162 view->setChart(timeCurve);
163 view->setRenderHint(QPainter::Antialiasing);
164 }
165
166 timeVector->resize(numValues);
167
168 for (i=0; i<numValues; i++ )
169 tempX[i] = (double)(i * crack_time) / numValues;
170
171 if (crack_time == 0) crack_time = 1;
172
173 for (lnd = list->head; lnd != 0; lnd = lnd->next) {
174 hsh_time = *(int*)(lnd->data);
175 i = (int)floor(hsh_time * numValues / crack_time);
176 tempY[(i >= numValues) ? numValues-1 : i] += 1.0;
177 }
178
179 for (i=1; i<numValues; i++) {
180 tempY[i] += tempY[i-1];
181 timeVector->replace(i, QPointF(tempX[i], tempY[i]));
182 }
183
184 timeSeries->replace(timeVector->mid(0, numValues));
185 if (crack_time > 1) {
186 timeAxisX->setRange(0, crack_time);
187 timeAxisY->setRange(0, tempY[numValues-1]);
188 }
189 timeAxisX->applyNiceNumbers();
190 timeAxisY->applyNiceNumbers();
191
192 }