diff options
author | EliteTK <tomasz.kramkowski@gmail.com> | 2015-06-19 19:12:12 +0100 |
---|---|---|
committer | EliteTK <tomasz.kramkowski@gmail.com> | 2015-06-19 19:12:12 +0100 |
commit | da87fcf25e0c94e57f00df84679cd6fadc56ed46 (patch) | |
tree | 3c53eea9db01039990455af870a2ca65e7e5a123 /genkeypairs.c | |
parent | 75d2e00662416224f4b745e0004f48f1fc1d9665 (diff) | |
parent | 7bf25fb8f0e4643a67894417a95d39e5901b1824 (diff) | |
download | c-stuff-da87fcf25e0c94e57f00df84679cd6fadc56ed46.tar.gz c-stuff-da87fcf25e0c94e57f00df84679cd6fadc56ed46.tar.xz c-stuff-da87fcf25e0c94e57f00df84679cd6fadc56ed46.zip |
Merge branch 'master' of https://github.com/EliteTK/c-stuff
Diffstat (limited to 'genkeypairs.c')
-rw-r--r-- | genkeypairs.c | 48 |
1 files changed, 29 insertions, 19 deletions
diff --git a/genkeypairs.c b/genkeypairs.c index f6043fe..12f145b 100644 --- a/genkeypairs.c +++ b/genkeypairs.c @@ -13,31 +13,41 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <ctype.h> #define MAXLIST 1000 #define MAXKEY 100 -int main(int argc, char **argv) +int getword(char *output, int maxlength) { - int c, i, ii, listsize; - char *list[MAXLIST]; - char *word = malloc(MAXKEY+1); - for(i=0; i<MAXLIST; i++) - if(!getword(word, MAXKEY)) - break; - else - memcpy(list[i]=malloc(strlen(word)+1), word, strlen(word)+1); - listsize = ++i; - for(i=0; i<listsize; i++) - for(ii=i+1; ii<listsize-1; ii++) - printf("./justkeys %s %s\n", list[i], list[ii]); + int c, p=0; + while((c = getchar())!=EOF && isalpha(c) && p<maxlength) + output[p++] = (char)c; + output[p] = '\0'; + return p; } -int getword(char *output, int maxlength) +int main(int argc, char **argv) { - int c, p=0; - while((c=getchar())!=EOF && isalpha(c) && p<maxlength) - output[p++] = (char)c; - output[p] = '\0'; - return p; + int i, ii, listsize; + char *list[MAXLIST], word[MAXKEY+1], *command, *ciphertext; + + if (argc != 3) { + fprintf(stderr, "Usage: %s <command> <ciphertext>", argv[0]); + exit(EXIT_FAILURE); + } + + command = argv[1]; + ciphertext = argv[2]; + + for(i=0; i<MAXLIST; i++) + if(!getword(word, MAXKEY)) + break; + else + memcpy(list[i] = malloc(strlen(word)+1), word, strlen(word)+1); + + listsize = ++i; + for(i=0; i<listsize; i++) + for(ii=i+1; ii<listsize-1; ii++) + printf("%s %s %s %s\n", command, list[i], list[ii], ciphertext); } |