//MAIN int main(int argc, char *argv[]){ int krypt; int pass, choose; char *phrase, *k_phrase; int i; if(argc != 2){ printf("Error! Use %s path/to/file", argv[0]); return 1; } phrase=malloc(sizeof(char) * 100); k_phrase = malloc(sizeof(char) *100); for(i=0; i<100; i++){ phrase[i]= ' '; k_phrase[i] = ' '; } krypt=make(argv[1]); printf("\n[1]krypt\n[2]dekrypt\n"); scanf("%i", &choose); if(choose != 1 && choose != 2){ printf("Error!"); return 1; } printf("\n\nEnter your key: "); scanf("%i", &pass); pass = getkey(krypt, pass); while(getchar() != '\n'); if(choose == 1){ printf("\nEnter phrase to krypt: "); fgets (phrase, 100, stdin); k_phrase = dokrypt(pass, phrase); save(argv[1], k_phrase); } else { printf("\nEnter phrase to dekrypt: "); fgets (k_phrase, 100, stdin); phrase = dekrypt(pass, k_phrase); } printf("\n\nKrypted: %s\n", k_phrase); printf("Dekrypted: %s\n\n", phrase); return 0; }
int main(int argc, const char * argv[]) { int move; char str[4096]; char buf[4096]; printf("please use the following commands: \ninput [string]\ncode [number]\n"); do { printf("$ "); getInput(buf,sizeof(buf)); if (!strncmp("input ", buf, 6)) { sscanf(buf+6,"%s",str); } else if(!strncmp("code ",buf,5)) { sscanf(buf+5,"%d",&move); if(move > 0) { krypt(str,move); } else { dekrypt(str, -move); } puts(str); } } while (strcmp(buf,"quit\n")); return 0; }