passgen/passgen.cpp

63 lines
1.2 KiB
C++
Raw Normal View History

2024-04-28 10:32:48 +00:00
#include <format>
2024-04-28 10:01:50 +00:00
#include <iostream>
2024-04-28 10:32:48 +00:00
#include <fstream>
2024-04-28 11:53:52 +00:00
#include <random>
2024-04-28 10:32:48 +00:00
#include <string>
#include <vector>
2024-04-28 10:01:50 +00:00
2024-04-28 11:03:20 +00:00
#include "pcg_random.hpp"
2024-04-28 10:32:48 +00:00
std::vector<std::string> readWordlist(std::string filePath)
{
std::vector<std::string> map;
std::ifstream file(filePath);
if (file.is_open()) {
std::string line;
while (std::getline(file, line)) {
map.push_back(line);
}
} else {
std::cout << std::format("ERROR: failed op open '{}'\n", filePath);
}
return map;
}
int main(int argc, char *argv[]) {
std::string path;
2024-04-28 11:53:52 +00:00
int count;
2024-04-28 10:32:48 +00:00
2024-04-28 11:53:52 +00:00
if (argc == 3) {
2024-04-28 10:32:48 +00:00
path = argv[1];
2024-04-28 11:53:52 +00:00
count = atoi(argv[2]);
2024-04-28 11:03:20 +00:00
} else if (argc == 1) {
2024-04-28 10:32:48 +00:00
path = "eff_large_wordlist.txt";
2024-04-28 11:53:52 +00:00
count = 5;
2024-04-28 11:03:20 +00:00
} else {
2024-04-28 11:53:52 +00:00
std::cout << "usage: passgen <wordlist_path> <wordcount>\n";
2024-04-28 11:03:20 +00:00
return 1;
2024-04-28 10:32:48 +00:00
}
std::vector<std::string> wordlist = readWordlist(path);
if (wordlist.size() == 0) {
return 1;
}
2024-04-28 11:53:52 +00:00
for (int i = 0; i < count; i++) {
pcg_extras::seed_seq_from<std::random_device> seed_source;
pcg32 rng(seed_source);
int random_int = std::uniform_int_distribution<int>(0, wordlist.size())(rng);
std::cout << wordlist[random_int];
if (i+1 == count) {
std::cout << "\n";
} else {
std::cout << "-";
}
}
2024-04-28 10:01:50 +00:00
}