diff options
-rw-r--r-- | .gitignore | 52 | ||||
-rw-r--r-- | passgen.c | 66 |
2 files changed, 118 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..91b4db5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,52 @@ +# Prerequisites
+*.d
+
+# Object files
+*.o
+*.ko
+*.obj
+*.elf
+
+# Linker output
+*.ilk
+*.map
+*.exp
+
+# Precompiled Headers
+*.gch
+*.pch
+
+# Libraries
+*.lib
+*.a
+*.la
+*.lo
+
+# Shared objects (inc. Windows DLLs)
+*.dll
+*.so
+*.so.*
+*.dylib
+
+# Executables
+*.exe
+*.out
+*.app
+*.i*86
+*.x86_64
+*.hex
+
+# Debug files
+*.dSYM/
+*.su
+*.idb
+*.pdb
+
+# Kernel Module Compile Results
+*.mod*
+*.cmd
+.tmp_versions/
+modules.order
+Module.symvers
+Mkfile.old
+dkms.conf
\ No newline at end of file diff --git a/passgen.c b/passgen.c new file mode 100644 index 0000000..f4f8960 --- /dev/null +++ b/passgen.c @@ -0,0 +1,66 @@ +#include <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <time.h>
+#include <unistd.h>
+
+#define DEFAULT_GRAMMAR "Cvccvc!##"
+
+// i, o excluded due to potentially confusing 1/l/i + 0/o
+#define VOWELS "aeuy"
+#define CONSONANTS "bcdfghkmnprstvwxz"
+#define NUMBERS "1234567890"
+#define SYMBOLS "@#$%^&*_-+=()[]{}"
+
+int main(int argc, char *argv[])
+{
+ char *grammar = DEFAULT_GRAMMAR;
+ int grammar_size = sizeof(DEFAULT_GRAMMAR)-1;
+
+ char password[grammar_size];
+
+ // seed RNG; this isn't very good, but it's enough
+ srand(time(NULL) << 2 + getpid() % 420 - 69);
+
+ for (int i = 0; i < grammar_size; ++i) {
+ char c = grammar[i];
+
+ bool caps = false;
+ if (c >= 'A' && c <= 'Z') {
+ caps = true;
+ c += 'a' - 'A';
+ }
+
+ char *class;
+ int class_size = 0;
+#define setClass(cl) \
+ class = cl; \
+ class_size = sizeof(cl)-1;
+
+ switch (c) {
+ case 'c':
+ setClass(CONSONANTS);
+ break;
+ case 'v':
+ setClass(VOWELS);
+ break;
+ case '!':
+ setClass(SYMBOLS);
+ break;
+ case '#':
+ setClass(NUMBERS);
+ break;
+ default:
+ printf("ERROR: Invalid grammar character '%C'.\n", c);
+ return 1;
+ }
+
+ do {
+ password[i] = class[rand() % class_size] - (caps ? 'a' - 'A' : 0);
+ } while (i != 0 && password[i] == password[i-1]);
+ }
+
+ printf("%s\n", password);
+
+ return 0;
+}
|