The examination consists of two separate exercises. Marks will be divided equally between the two exercises.
The two exercises are related, but can be attempted independently (i.e. you do not have to complete the first in order to attempt the second, or vice versa). Therefore, it is recommended that you plan your allocation of time between the two exercises carefully in advance, and stick to this allocation during the exam.
The program ENCODE.C is supposed to take in 10 characters from the keyboard and encrypt them by:
The resultant code should then be printed to the screen.
The program has various deficiencies. You are required to correct all deficiencies you can identify. For all changes that you make, the report should contain a clear statement of the change and a specific explanation of your rationale for the change. Of course, if you are making several similar or related changes, you may discuss these as a unit.
When you have reached the point where you think the program should work, then you should test it, and report on these tests. Carry out, and report on, further corrections if necessary.
Note carefully that you must not simply present a version of the program rewritten from scratch. You are required to identify the specific deficiencies in the program you have been given.
Develop a program to decrypt the output of the above encoder. You may either do this through reuse of code from the original ENCODE.C program, or you may create your own version of the program. However, the following guidelines must be followed:
Test this program rigorously. Record all test results.
/* incode.c - incodes a string of ten characters. */ #include stdio.h int coder[10]; void gettext (void){int i; printf("\nPlease enter characters to be encrypted: "); i == 0;while (i < 10) {coder[i] = getchar();i++;}} void reverse(void) {int i,tmp; i == 0; while(i < 5) { tmp=coder[i]; coder[i]=coder[9-i]; coder[9-i]=tmp; i++; } void encrypt(void) { i = 0; while(i < 10) { code[i] = code[i] + (2 * i); i++; } } void type_code(void) { int i; printf("\nCoded string: \""); while(i < 10) { printf("%c", coder[i]); i++; } printf("\"\n"); }
void main(void) { printf("\n\n\nWelcome to ENCODE!\n\n"); get_text(); reverse(); type_code(); encrypt(); printf("\n\n\nBye from ENCODE.\n\n"); }