/* Atanas Dimtirov Assignment 1 CSCI 6900 Due: 8/24/04 Completed: 8/24/04 */ #include #include #include "./crypt.h" int main() { //time related time_t *now; struct timeval start_time, stop_time; double en, st; double microsec = 1000000.0; //input files FILE *file_ptr1, *file_ptr2, *file_ptr3; char message[9]; // temp storage //bit values int values[64]; //for testing bit manipulations char bits[]={ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64 }; //passed to setkey char key[]={ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64 }; int i, j, k,l; //counters etc. double sum=0; //sum of all exec times srand(getpid()); //open file and print random (100x8-byte) characters file_ptr1=fopen("./input.txt", "w"); for (i=0; i<100; i++) { for(j=0; j<8; j++) fprintf(file_ptr1, "%d", rand()/10000); } fclose(file_ptr1); file_ptr1=fopen("./input.txt", "r"); //input file file_ptr2=fopen("./output.txt", "w");//output file file_ptr3=fopen("./times.txt", "w"); //output file containing exec times and average exec time fflush(stdout); //till the end of the file while(fgets(message, 9, file_ptr1) != NULL) { fflush(stdout); k=0; //separate the bits for (i=0; i<8; i++) { for (j=0; j<8; j++) { values[k]=(message[i] >> (7 - j)) & 1; k++; } } fflush(stdout); //set the key setkey(key); //write the input 8 bytes as binary for (i=0; i<64; i++) fprintf(file_ptr2, "%x", bits[i]=values[i]); fprintf(file_ptr2, "\n"); //time the encrypt() function gettimeofday(&start_time, (struct timezone *) 0); encrypt(bits); gettimeofday(&stop_time, (struct timezone *)0); //write the output 8 bytes in binary for (i=0; i<64; i++) fprintf(file_ptr2, "%x", bits[i]); fprintf(file_ptr2, "\n\n"); //time tracking related st = start_time.tv_sec + (start_time.tv_usec/microsec); en = stop_time.tv_sec + (stop_time.tv_usec/microsec); //print the exec time fprintf(file_ptr3, "real time: %f\n", en-st); //add the exec time to the sum of all exec times sum=sum+en-st; } //write the average time fprintf(file_ptr3, "\naverage real time: %f\n\n", sum/100); //close the files fclose(file_ptr1); fclose(file_ptr2); fclose(file_ptr3); exit(0); }