driver.c

来自「并行算法实验用的源代码」· C语言 代码 · 共 115 行

C
115
字号
/******************************************************************** File:        driver - main included - Program use: Crypt Lab #:       3 Description: This file represents a skelleton driver for              the encryption function. See the file labled              encrypt.c for it's specifications.              One note on the encryption function. It will              only work properly with even length strings.              So, if you test it with your own strings be              sure to use even number of strings. If I can              find a fix for this I will pass it along, however              it is inconsequetial to this lab.              Also, your are limited to strings of length 50.              Again, if you wish to change this go ahead. Notes:       Also included with this file are two makefiles:              makefile and makefile.mpicc. The serial version              of this program can be compiled with the              file labled makefile while the file makefile.mpicc              is the version you should use in compilling you              parallel version. You may make changes to either              of these makefiles, but you must submit them              both.********************************************************************/#include <stdlib.h>#include <stdio.h>// defines#define MATCH 0#define SIZE  60/*****   N is a constant used in all the encode and decode   keys provided in this lab*****/#define N     34169 /*******************************Function:    driver - main -********************************/void main (int argc, char **argv){  unsigned long int enKey, deKey;  int           counter;  char          ch, inStr[SIZE], *tmpStr, outStr[SIZE];  FILE          *in1, *in2, *out;    if (argc != 3){       printf("usage: Crypt <input1> <input2>\n");       exit(1);     }  /****  The encrypted versions of the given text files were  encrypted with the enKey.  Your job is to find the deKey (decrypt key). You do  not need the enKey to find dekey.  Below is an example two key pair.  These keys will encrypt and decrypt the code for codeText1 and  codeEnc1 respectively. This is ment as an example   how the program works  ***/  enKey = 7253;  deKey = 12653;    /********************      Input file containing the unencrypted string    ********************/    strcpy(inStr, "");    if(! (in1= fopen(argv[1], "rb")) ){ perror(argv[1]); exit(1); }    counter = 0;    ch      = getc(in1);    while(ch != EOF){      inStr[counter] = ch;      ch = getc(in1);      counter++;    }    counter--;    inStr[counter] = '\0';    fclose(in1);    /********************      Output file containing the string from the      input file encrypted    ********************/    strcpy(outStr, "");    if(! (in2= fopen(argv[2], "rb")) ){ perror(argv[2]); exit(1); }    counter = 0;    ch      = getc(in2);    while(ch != EOF){      outStr[counter] = ch;      ch = getc(in2);      counter++;    }    outStr[counter] = '\0';    fclose(in2);    /** run encrypt function    ***/    tmpStr = (char *)cryptString(outStr, deKey, N);    if(MATCH == strcmp(inStr, tmpStr)){      printf("%d\n%s\n", deKey, tmpStr);    }else{      printf("NO MATCH\n");    }    }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?