Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cppack
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
passwords
cppack
Commits
d6251be8
Commit
d6251be8
authored
Feb 5, 2020
by
Mathieu Valois
Browse files
Options
Downloads
Patches
Plain Diff
use vector instead of C array
parent
0667f960
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
include/MainWindow.h
+4
-5
4 additions, 5 deletions
include/MainWindow.h
include/Statsgen.h
+5
-5
5 additions, 5 deletions
include/Statsgen.h
src/core/Statsgen.cpp
+26
-28
26 additions, 28 deletions
src/core/Statsgen.cpp
with
35 additions
and
38 deletions
include/MainWindow.h
+
4
−
5
View file @
d6251be8
...
...
@@ -28,18 +28,17 @@ class ProgressThread : public QThread
void
run
()
{
unsigned
int
progress
=
0
;
uint64_t
processed
=
0
;
const
int
nbthreads
=
_s
.
getNbThreads
();
const
struct
ThreadData
*
td
=
_s
.
getThreadsData
();
const
std
::
vector
<
ThreadData
>&
td
=
_s
.
getThreadsData
();
while
(
!
_s
.
allStarted
()){
msleep
(
500
);
}
const
uint64_t
nblines
=
td
[
nbthreads
-
1
]
.
lineEnd
;
const
uint64_t
nblines
=
td
.
back
()
.
lineEnd
;
while
(
!
_s
.
allFinished
()){
processed
=
0
;
for
(
int
i
=
0
;
i
<
nbthreads
;
++
i
){
processed
+=
t
d
[
i
]
.
total_counter
;
for
(
ThreadData
t
:
td
){
processed
+=
t
.
total_counter
;
}
progress
=
(
int
)
percentage
(
processed
,
nblines
);
_qpb
.
setValue
(
progress
);
...
...
This diff is collapsed.
Click to expand it.
include/Statsgen.h
+
5
−
5
View file @
d6251be8
...
...
@@ -23,8 +23,6 @@
#include
"SecurityRules.h"
#include
"ThreadData.h"
#define MAX_THREADS 32
struct
PasswordStats
{
int
pass_length
=
0
;
...
...
@@ -143,15 +141,17 @@ public:
inline
const
StringOccurrence
&
getStatsCharsets
()
const
{
return
td
[
0
].
charactersets
;
}
inline
const
StringOccurrence
&
getStatsSimple
()
const
{
return
td
[
0
].
simplemasks
;
}
inline
const
StringOccurrence
&
getStatsAdvanced
()
const
{
return
td
[
0
].
advancedmasks
;
}
inline
const
ThreadData
*
getThreadsData
()
const
{
return
td
;
}
inline
const
std
::
vector
<
ThreadData
>&
getThreadsData
()
const
{
return
td
;
}
inline
bool
allFinished
()
const
{
return
finished
==
nbThread
;
}
inline
bool
allStarted
()
const
{
return
started
;
}
bool
operator
==
(
const
Statsgen
&
other
)
const
;
private
:
std
::
string
filename
;
// contains all the stats
ThreadData
td
[
MAX_THREADS
];
// results of the computation
ThreadData
results
;
// Data computed from within a thread, for read-accessibility
std
::
vector
<
ThreadData
>
td
;
// Filters
...
...
This diff is collapsed.
Click to expand it.
src/core/Statsgen.cpp
+
26
−
28
View file @
d6251be8
...
...
@@ -63,6 +63,8 @@ void Statsgen::configureThread(ThreadData& td) const {
}
int
Statsgen
::
generate_stats
()
{
td
=
vector
<
ThreadData
>
(
nbThread
);
results
=
ThreadData
();
finished
=
0
;
started
=
false
;
uint64_t
nbline
=
0
;
...
...
@@ -74,7 +76,7 @@ int Statsgen::generate_stats() {
}
}
pthread_t
threads
[
MAX_THREADS
]
;
vector
<
pthread_t
>
threads
(
nbThread
)
;
// split stdin into nbThread files on disk
if
(
is_stdin
){
...
...
@@ -127,13 +129,11 @@ int Statsgen::generate_stats() {
cerr
<<
"[ERROR] unable to join,"
<<
rc
<<
endl
;
exit
(
-
1
);
}
if
(
i
>=
1
){
td
[
0
]
+=
td
[
i
];
}
results
+=
td
[
i
];
finished
++
;
}
if
(
!
td
[
0
]
.
total_counter
)
{
if
(
!
results
.
total_counter
)
{
cerr
<<
"[ERROR] Empty file or not existing file"
<<
endl
;
return
0
;
}
...
...
@@ -142,60 +142,59 @@ int Statsgen::generate_stats() {
}
void
Statsgen
::
print_stats
()
{
ThreadData
&
data
=
td
[
0
];
int
count
;
float
perc
=
percentage
(
data
.
total_filter
,
data
.
total_counter
);
float
perc
=
percentage
(
results
.
total_filter
,
results
.
total_counter
);
cout
<<
"
\n\t
Selected "
<<
data
.
total_filter
<<
" on "
<<
data
.
total_counter
<<
" passwords
\t
("
cout
<<
"
\n\t
Selected "
<<
results
.
total_filter
<<
" on "
<<
results
.
total_counter
<<
" passwords
\t
("
<<
perc
<<
" %)"
<<
endl
;
cout
<<
"
\n
Security rules : "
<<
endl
;
cout
<<
"
\t
Minimal length of a password: "
<<
data
.
sr
.
minLength
<<
endl
;
cout
<<
"
\t
Minimum of special characters in a password: "
<<
data
.
sr
.
minSpecial
<<
endl
;
cout
<<
"
\t
Minimum of digits in a password: "
<<
data
.
sr
.
minDigit
<<
endl
;
cout
<<
"
\t
Minimum of lower characters in a password: "
<<
data
.
sr
.
minLower
<<
endl
;
cout
<<
"
\t
Minimum of upper characters in a password: "
<<
data
.
sr
.
minUpper
<<
endl
;
cout
<<
"
\t
Minimal length of a password: "
<<
results
.
sr
.
minLength
<<
endl
;
cout
<<
"
\t
Minimum of special characters in a password: "
<<
results
.
sr
.
minSpecial
<<
endl
;
cout
<<
"
\t
Minimum of digits in a password: "
<<
results
.
sr
.
minDigit
<<
endl
;
cout
<<
"
\t
Minimum of lower characters in a password: "
<<
results
.
sr
.
minLower
<<
endl
;
cout
<<
"
\t
Minimum of upper characters in a password: "
<<
results
.
sr
.
minUpper
<<
endl
;
float
perce
=
percentage
(
data
.
sr
.
nbSecurePassword
,
data
.
total_counter
);
cout
<<
"
\n\t\t
--> "
<<
data
.
sr
.
nbSecurePassword
<<
" passwords
\t
("
<<
perce
<<
" %) respect the security rules
\n
"
<<
endl
;
float
perce
=
percentage
(
results
.
sr
.
nbSecurePassword
,
results
.
total_counter
);
cout
<<
"
\n\t\t
--> "
<<
results
.
sr
.
nbSecurePassword
<<
" passwords
\t
("
<<
perce
<<
" %) respect the security rules
\n
"
<<
endl
;
cout
<<
"
\n
min - max
\n
"
<<
endl
;
cout
<<
setw
(
43
)
<<
right
<<
"digit: "
<<
setw
(
2
)
<<
right
<<
data
.
minMaxValue
.
mindigit
<<
" - "
<<
data
.
minMaxValue
.
maxdigit
<<
endl
;
<<
setw
(
2
)
<<
right
<<
results
.
minMaxValue
.
mindigit
<<
" - "
<<
results
.
minMaxValue
.
maxdigit
<<
endl
;
cout
<<
setw
(
43
)
<<
right
<<
"lower: "
<<
setw
(
2
)
<<
right
<<
data
.
minMaxValue
.
minlower
<<
" - "
<<
data
.
minMaxValue
.
maxlower
<<
endl
;
<<
setw
(
2
)
<<
right
<<
results
.
minMaxValue
.
minlower
<<
" - "
<<
results
.
minMaxValue
.
maxlower
<<
endl
;
cout
<<
setw
(
43
)
<<
right
<<
"upper: "
<<
setw
(
2
)
<<
right
<<
data
.
minMaxValue
.
minupper
<<
" - "
<<
data
.
minMaxValue
.
maxupper
<<
endl
;
<<
setw
(
2
)
<<
right
<<
results
.
minMaxValue
.
minupper
<<
" - "
<<
results
.
minMaxValue
.
maxupper
<<
endl
;
cout
<<
setw
(
43
)
<<
right
<<
"special: "
<<
setw
(
2
)
<<
right
<<
data
.
minMaxValue
.
minspecial
<<
" - "
<<
data
.
minMaxValue
.
maxspecial
<<
endl
;
<<
setw
(
2
)
<<
right
<<
results
.
minMaxValue
.
minspecial
<<
" - "
<<
results
.
minMaxValue
.
maxspecial
<<
endl
;
cout
<<
"
\n
Statistics relative to length:
\n
"
<<
endl
;
showMap
(
data
.
length
,
top
,
data
.
total_counter
,
hiderare
,
count
);
showMap
(
results
.
length
,
top
,
results
.
total_counter
,
hiderare
,
count
);
cout
<<
"
\n
Statistics relative to charsets:
\n
"
<<
endl
;
showMap
(
data
.
charactersets
,
-
1
,
data
.
total_counter
,
hiderare
,
count
);
showMap
(
results
.
charactersets
,
-
1
,
results
.
total_counter
,
hiderare
,
count
);
cout
<<
"
\n
Statistics relative to simplemasks:
\n
"
<<
endl
;
showMap
(
data
.
simplemasks
,
top
,
data
.
total_counter
,
hiderare
,
count
);
showMap
(
results
.
simplemasks
,
top
,
results
.
total_counter
,
hiderare
,
count
);
if
(
limitSimplemask
>
0
)
{
cout
<<
endl
;
readResult
(
data
.
simplemasks
[
"othermasks"
],
"othermasks"
,
count
,
data
.
total_counter
,
hiderare
);
readResult
(
results
.
simplemasks
[
"othermasks"
],
"othermasks"
,
count
,
results
.
total_counter
,
hiderare
);
}
cout
<<
"
\n
Statistics relative to advancedmask:
\n
"
<<
endl
;
showMap
(
data
.
advancedmasks
,
top
,
data
.
total_counter
,
hiderare
,
count
);
showMap
(
results
.
advancedmasks
,
top
,
results
.
total_counter
,
hiderare
,
count
);
if
(
!
outfile_name
.
empty
()){
locale
::
global
(
locale
(
"C"
));
ofstream
outfile_stream
(
outfile_name
);
map
<
uint64_t
,
string
,
greater
<
uint64_t
>>
reverse
=
flip_map
(
data
.
advancedmasks
);
map
<
uint64_t
,
string
,
greater
<
uint64_t
>>
reverse
=
flip_map
(
results
.
advancedmasks
);
for
(
pair
<
uint64_t
,
string
>
it
:
reverse
){
if
(
it
.
second
==
"othermasks"
)
continue
;
outfile_stream
<<
it
.
second
<<
","
<<
it
.
first
<<
endl
;
...
...
@@ -205,7 +204,7 @@ void Statsgen::print_stats() {
if
(
limitAdvancedmask
>
0
)
{
cout
<<
endl
;
readResult
(
data
.
advancedmasks
[
"othermasks"
],
"othermasks"
,
count
,
data
.
total_counter
,
hiderare
);
readResult
(
results
.
advancedmasks
[
"othermasks"
],
"othermasks"
,
count
,
results
.
total_counter
,
hiderare
);
}
}
...
...
@@ -347,13 +346,12 @@ uint64_t nbline_file(const string & filename) {
cerr
<<
"[ERROR] There was an error reading the file at line "
<<
nb
<<
endl
;
return
0
;
}
return
nb
;
}
bool
Statsgen
::
operator
==
(
const
Statsgen
&
o
)
const
{
return
td
[
0
]
==
o
.
td
[
0
]
;
return
results
==
o
.
results
;
}
bool
SecurityRules
::
operator
==
(
const
SecurityRules
&
o
)
const
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment