password-analyzer/defs.hpp

59 lines
1.6 KiB
C++
Raw Normal View History

2023-11-03 21:05:08 +08:00
#ifndef DEFS_HPP
#define DEFS_HPP
2023-11-04 00:22:45 +08:00
#include <chrono>
#include <memory>
2023-11-03 21:05:08 +08:00
#include <string>
2023-11-04 00:22:45 +08:00
#include <utility>
2023-11-03 21:05:08 +08:00
#if __has_include(<generator>)
#include <generator>
#else
#include "generator.hpp"
#endif
#include "spdlog/spdlog.h"
#include "magic_enum.hpp"
using std::operator""s;
using std::operator""sv;
enum class DataSource { CSDN, YAHOO };
2023-11-04 00:22:45 +08:00
struct Timer {
std::chrono::time_point<std::chrono::steady_clock> begin;
std::string name;
explicit Timer(std::string name) {
spdlog::info("[{}] start...", name);
this->name = name;
this->begin = std::chrono::steady_clock::now();
}
~Timer() {
auto end = std::chrono::steady_clock::now();
spdlog::info("[{}] time usage: {}ms", name,
std::chrono::duration_cast<std::chrono::milliseconds>(end - begin).count());
}
};
// the fucking magic with macro
#define CONCAT_IMPL(x, y) x##y
#define MACRO_CONCAT(x, y) CONCAT_IMPL(x, y)
#define timeit(name) std::shared_ptr<Timer> MACRO_CONCAT(_timer_, __COUNTER__)(new Timer(name))
2023-11-03 21:11:37 +08:00
struct Cord {
int x, y;
bool operator==(const Cord &rhs) const { return x == rhs.x && y == rhs.y; }
};
2023-11-04 00:22:45 +08:00
bool is_num(char c);
bool is_alpha(char c);
std::string tolower(const std::string &raw);
2023-11-03 21:05:08 +08:00
std::generator<std::string> passwords(const DataSource &source);
2023-11-03 22:17:53 +08:00
void stat_date(const DataSource &source);
2023-11-03 21:11:37 +08:00
void stat_keystroke(const DataSource &source);
2023-11-03 21:06:09 +08:00
void stat_length(const DataSource &source);
2023-11-03 21:11:37 +08:00
void stat_struct(const DataSource &source);
2023-11-04 00:22:45 +08:00
void stat_word(const DataSource &source);
2023-11-03 21:11:37 +08:00
2023-11-03 21:05:08 +08:00
#endif // DEFS_HPP