diff options
author | Tomasz Kramkowski <tk@the-tk.com> | 2015-04-03 12:01:14 +0200 |
---|---|---|
committer | Tomasz Kramkowski <tk@the-tk.com> | 2015-04-03 12:01:14 +0200 |
commit | 70bb06ed33201cb9c420661a5d391f45706109f1 (patch) | |
tree | df7a9c826b47e78b420943ed5127c950fce9498f | |
parent | f8b900badcc505af67575d17e6c59abc92961327 (diff) | |
download | c-stuff-70bb06ed33201cb9c420661a5d391f45706109f1.tar.gz c-stuff-70bb06ed33201cb9c420661a5d391f45706109f1.tar.xz c-stuff-70bb06ed33201cb9c420661a5d391f45706109f1.zip |
genkeypairs: now more flexible
-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); } |