/* * CMPE 311 * F19 Discussion 5 * Created: 9/27/2019 1:17:11 PM */ #include "U0_UART.h" #include #include extern FILE uart_stream; /* declare uart_stream indicating that it is defined within project scope */ // constant char arrays transmitted via serial const char promptEncrypt[] = "Enter a password (U,D,L,R) [25 characters max]: \n"; const char promptCompare[] = "Enter the password: \n"; const char secretMessage[] = "Get started on Homework 2!!\n"; #define MAX_PASS_LENGTH 25 /* maximum length of user defined password */ // basic encryption function char* encrypt(char input[]){ int i = 0; while(input[i] != '\0'){ input[i] += 3; i++; } return input; } // basic decryption function char* decrypt(char stored[]){ int i = 0; while(stored[i] != '\0'){ stored[i] -= 3; i++; } return stored; } int main(void) { stderr = stdin = stdout = &uart_stream; /* re-map standard output, input, error */ UARTInit(); /* initialize the UART (set hardware specific configuration registers) */ printf(promptEncrypt); char input[MAX_PASS_LENGTH]; /* char array to store user defined password */ char guess[MAX_PASS_LENGTH]; /* char array to store user's password guess */ char* encrypted; /* char array to store encrypted user defined password */ char* decrypted; /* char array to store decrypted user defined password */ fgets(input, MAX_PASS_LENGTH, &uart_stream); /* user sets password */ encrypted = encrypt(input); /* encrypt password */ printf(promptCompare); fgets(guess, MAX_PASS_LENGTH, &uart_stream); /* user attempts to enter correct password */ decrypted = decrypt(encrypted); /* decrypt stored password */ /* [INSTRUCTIONS]: compare the decrypted password to the user's input using function strcmp(const char* str1, const char* str2) strcmp returns: (int = 0): strings are identical (int > 0): first non-matching char in str1 > str2 (int < 0): first non-matching char in str1 < str2 loop and re-prompt the user to enter a password while their entry does not match the decrypted password, when the passwords match the loop should exit and the secret message will be transmitted */ // transmits secret message printf("Secret Message: "); printf(secretMessage); return 0; }