Question: Please finish the code. */ #include #include void clearBuffer(); void encrypt(); void decrypt(); void printBinary(int number); void printOption(); void printArray(int arr[], int size); static int

Please finish the code.

*/ #include  #include  void clearBuffer(); void encrypt(); void decrypt(); void printBinary(int number); void printOption(); void printArray(int arr[], int size); static int month = 0; static int date = 0; static int century = 0; static int year = 0; static int secret = 0; int main(void) { char userChoice = ' '; int isQuit = 0; while(1 == 1){//Loop, for user choice: encryption / decryption printOption(); userChoice = getchar(); //get rid of the rest characters in the buffer clearBuffer(); //response to user choice switch(userChoice){ case '1': encrypt(); break; case '2': decrypt(); break; case 'q': isQuit = 1; break; default: break; } //quit if(isQuit == 1) { puts("Bye"); break;//break out the infinite while loop } //print final result printf("Date: %d-%d-%d%d, Secret: %#X, ",month, date, century, year, secret); printBinary(secret); //get rid of remaining characters in the buffer left by encrypt or decrypt clearBuffer(); } return EXIT_SUCCESS; } void clearBuffer(){ char garbage = ' '; while(garbage != ' '){ garbage = getchar(); } } /** encrypt(): Encrypt user entered date information into secret (i.e., one single integer) * */ void encrypt(){ puts("*********Encrypting a date!*************"); //Ask user for month, date, and year (4-digit year) puts("Enter month number:"); scanf("%d", &month);//month is already a pointer / address puts("Enter date number:"); scanf("%d", &date); puts("Enter 4-digit year number:"); scanf("%d", &year); //calculate century and 2-digit year century = year / 100; year = year % 100; /**************************Your job below *****************************/ //Encrypt month, date, century, and year into secret } void decrypt(){ puts("*********Decrypting a secret*********"); puts("Enter a secret number in hexadecimal form:"); scanf("%X", &secret); //Test with 0X0A081412 /**************************Your job below *****************************/ //Decryption: figure out the month, date, century, and year from the secret } void printBinary(int number){ int size = 8 * sizeof(int) ; int arr[size]; //get binary into the array int i = size - 1; while(i >= 0){ arr[i] = number & 01; number = number >> 1; //right-shift 1 bit i --; //decrement index } printArray(arr, size); } void printOption(){ puts("Enter your choice: " "\t1-Encrypt a Date; " "\t2-Decrypt a Date; " "\tq-Quit"); } void printArray(int arr[], int size){ int i = 0; for(; i < size; i ++){ printf("%d", arr[i]); } puts(""); }

Your job is to complete the missing code in the encrypt and decrypt methods: >>Encrypt month, date, century, and year into secret >>Decrypt secret to find out month, date, century, and year

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!