add length analyzer
This commit is contained in:
parent
78cd9404c5
commit
3e70825234
@ -58,6 +58,7 @@ include_directories(password-analyzer PRIVATE ${CMAKE_BINARY_DIR}/external)
|
|||||||
set(COMMON_SOURCES
|
set(COMMON_SOURCES
|
||||||
defs.hpp
|
defs.hpp
|
||||||
utils.cpp
|
utils.cpp
|
||||||
|
stat_length.cpp
|
||||||
)
|
)
|
||||||
set(COMMON_LIBRARIES
|
set(COMMON_LIBRARIES
|
||||||
magic_enum::magic_enum
|
magic_enum::magic_enum
|
||||||
|
1
defs.hpp
1
defs.hpp
@ -21,4 +21,5 @@ bool is_alpha(char c);
|
|||||||
|
|
||||||
std::generator<std::string> passwords(const DataSource &source);
|
std::generator<std::string> passwords(const DataSource &source);
|
||||||
|
|
||||||
|
void stat_length(const DataSource &source);
|
||||||
#endif // DEFS_HPP
|
#endif // DEFS_HPP
|
||||||
|
16
stat_length.cpp
Normal file
16
stat_length.cpp
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#include <algorithm>
|
||||||
|
#include <map>
|
||||||
|
#include <vector>
|
||||||
|
#include "defs.hpp"
|
||||||
|
|
||||||
|
void stat_length(const DataSource &source) {
|
||||||
|
spdlog::info("stat_length({})", magic_enum::enum_name(source));
|
||||||
|
|
||||||
|
std::map<size_t, size_t> stat;
|
||||||
|
for (auto const &password : passwords(source)) ++stat[password.size()];
|
||||||
|
|
||||||
|
std::vector<std::pair<size_t, size_t>> vec(stat.begin(), stat.end());
|
||||||
|
std::sort(vec.begin(), vec.end(), [](auto const &lhs, auto const &rhs) { return lhs.second > rhs.second; });
|
||||||
|
|
||||||
|
for (auto const &[length, count] : vec | std::views::take(10)) spdlog::info("{}: {}", length, count);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user