aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorfoswret <foswret@posteo.com>2025-06-22 15:05:58 -0500
committerfoswret <foswret@posteo.com>2025-06-22 15:05:58 -0500
commit57c23dcedeb448769e66761a5e2faa7320427b9f (patch)
tree16b8004e61e9c413f2914ae050bc3fbd9b8ecde0 /main.c
parent2e84588ec83b453e9c1a667841200b7d77260621 (diff)
added key image to README.md
Diffstat (limited to 'main.c')
-rw-r--r--main.c105
1 files changed, 105 insertions, 0 deletions
diff --git a/main.c b/main.c
new file mode 100644
index 0000000..66bb64e
--- /dev/null
+++ b/main.c
@@ -0,0 +1,105 @@
+#include <sodium/randombytes.h>
+#include <stdio.h>
+#include <string.h>
+#include <sodium.h>
+#include <unistd.h>
+#include <ctype.h> //To Upper
+
+
+long count_lines(FILE *File) {
+ char c;
+ long line_counter = 0;
+ while ((c = getc(File)) != EOF) {
+ if (c == '\n') {
+ line_counter++;
+ }
+ }
+ return(line_counter);
+}
+
+void randomize_case(char *a) { // Accepts a string as input
+ for (int i = 0; i < strlen(a); i++) {
+ int coin = randombytes_uniform(2); // Decide if the current character will be capitalized or lowercase
+ if (coin == 1) {
+ a[i] = toupper(a[i]);
+ }
+ }
+}
+
+void generate_integers(void) {
+ int length = 5; // TO-DO: Make random eventually
+ for (int i=0; i<length; i++) {
+ int random = randombytes_uniform(length);
+ printf("%d", random);
+ }
+}
+
+void generate_characters(char *set) {
+ int random_length;
+ // while (random_length <= 3) random_length
+ for (int i = 0; i < 5; i++) {
+ int random_character = randombytes_uniform(strlen(set));
+ printf("%c", set[random_character]);
+ }
+}
+
+int main (int argc, char **argv) {
+ char a, arg, str[20];
+ long line_counter, line_total, r;
+ FILE *words;
+
+ int index;
+ int f_flag = 0;
+ int c;
+ opterr = 0;
+
+ char character_set[28] = "!@#$%^&*()_-+={}[]|~`<,>.?:;";
+ char letter_set[26] = "abcdefghijklmnopqrstuvwxyz";
+
+ while ((c = getopt (argc, argv, "n")) != -1)
+ switch(c) {
+ case 'n':
+ case '?':
+ if (optopt == 'c')
+ fprintf (stderr, "Option -%c requires an argument.\n", optopt);
+ else if (isprint (optopt))
+ fprintf (stderr, "Unknown option '-%c',\n", optopt);
+ else
+ fprintf (stderr, "Unknown option character '\\x%x.\n", optopt);
+ return 1;
+ default:
+ abort();
+ }
+
+ if (sodium_init() < 0) return 1;
+ words = fopen("word_list.txt", "r");
+
+ line_total = count_lines(words);
+ fseek(words, 0, SEEK_SET); // Reset pointer to beginning of file
+
+ char temp[2]; // Cannot copy c directly to str. needs a buffer
+ temp[1] = '\0'; // Makes the array a string
+
+ r = randombytes_uniform(line_total + 1); // Generates random line number to use for string
+
+ while ((a = getc(words)) != EOF) {
+ int i;
+ temp[0] = a;
+ if ((r == i) && (a != '\n')) {
+ strcat(str, temp);
+ }
+ if (a == '\n') {
+ i++; }
+ }
+
+ randomize_case(str);
+ generate_integers();
+ generate_characters(letter_set);
+ // printf("%s", str);
+ generate_characters(character_set);
+
+ printf("\n");
+ fseek(words, 0, SEEK_SET); // Reset pointer to beginning of file //
+ fclose(words);
+}
+