From 1d19ad496f8cbfd48ffaaf26891d42d945fe2d05 Mon Sep 17 00:00:00 2001 From: Mans Ziesel Date: Sun, 28 Apr 2024 13:53:52 +0200 Subject: [PATCH] Compile to .exe --- .gitignore | 1 + Makefile | 27 ++++++++++++++++++++++++--- passgen.cpp | 23 ++++++++++++++++++++--- 3 files changed, 45 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index d55d984..83575a7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *.o +*.exe passgen .cache/ diff --git a/Makefile b/Makefile index 2410413..b7435db 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,34 @@ TARGETS = passgen +BINARYOUT_TARGETS = passgen.o CPPFLAGS += -I./include CXXFLAGS += -std=c++20 -O2 -CC = $(CXX) # Cheat so that linking uses the C++ compiler -all: $(TARGETS) + +ifeq ($(OS),Windows_NT) + CC = x86_64-w64-mingw32-g++ + LD = x86_64-w64-mingw32-g++ + EXE_EXT = .exe +else + CC = g++ + LD = g++ + EXE_EXT = +endif + +all: $(TARGETS)$(EXE_EXT) + +run: + ./passgen$(EXE_EXT) clean: - rm -f *.o $(TARGETS) $(BINARYOUT_TARGETS) + rm -f *.o *.exe $(TARGETS) $(BINARYOUT_TARGETS) + +passgen.exe: passgen.o + $(LD) -static-libgcc -static-libstdc++ passgen.o -o passgen.exe + +passgen: passgen.o + $(LD) passgen.o -o passgen passgen.o: passgen.cpp ./include/pcg_random.hpp \ ./include/pcg_extras.hpp ./include/pcg_uint128.hpp + $(CC) $(CPPFLAGS) $(CXXFLAGS) -c -o passgen.o passgen.cpp diff --git a/passgen.cpp b/passgen.cpp index 72c110d..bbfbb9e 100644 --- a/passgen.cpp +++ b/passgen.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -25,13 +26,16 @@ std::vector readWordlist(std::string filePath) int main(int argc, char *argv[]) { std::string path; + int count; - if (argc == 2) { + if (argc == 3) { path = argv[1]; + count = atoi(argv[2]); } else if (argc == 1) { path = "eff_large_wordlist.txt"; + count = 5; } else { - std::cout << "usage: passgen \n"; + std::cout << "usage: passgen \n"; return 1; } @@ -41,5 +45,18 @@ int main(int argc, char *argv[]) { return 1; } - std::cout << wordlist[0] << "\n"; + for (int i = 0; i < count; i++) { + pcg_extras::seed_seq_from seed_source; + pcg32 rng(seed_source); + + int random_int = std::uniform_int_distribution(0, wordlist.size())(rng); + + std::cout << wordlist[random_int]; + + if (i+1 == count) { + std::cout << "\n"; + } else { + std::cout << "-"; + } + } }