/* COSC 350 February 4, 1998 */ #include #include #include #include #define AlphSize 27 int char_to_index(char ch) { if ((ch == '_') || (ch == '*')) { return (int)26; } else if ((ch >= 'A') && (ch <= 'Z')) { return (int)(ch - 'A'); } /* else { fprintf(stderr, "Invalid character in file.\n"); exit(1); }*/ return 0; } int main(int argc, char *argv[]) { FILE *infile; int period, counter; long **Counts, *Tally, N; long Total[AlphSize]; char next, error; int i, j; double IC; /* Index of Coincidence */ double total; double temp; double f; int totalchars; error = 0; if (argc > 3) { error = 1; } else if ((infile = fopen(argv[1], "r")) == NULL) { error = 1; } else if ((period = atoi(argv[2])) <= 0) { error = 1; } if (error) { fprintf(stderr, "Usage: freq input_file period\n\n"); fprintf(stderr, " where input_file is the name of the file containing the data, and\n"); fprintf(stderr, " period is the number of alphabets to count.\n\n"); fprintf(stderr, "The results are placed on standard output.\n\n"); fprintf(stderr, "For example:\n"); fprintf(stderr, " freq cipher.txt 3 >results\n"); exit(1); } fprintf(stderr, "Initializing arrays..."); if ((Counts = (long **)malloc(period * sizeof(long *))) == NULL) { error = 1; } for (i=0; i