You want to send a secret message to your friend. You decide to agree on a Solut
ID: 641723 • Letter: Y
Question
You want to send a secret message to your friend. You decide to agree on a
Explanation / Answer
This might help #include #include #include void entryData(); void decodeFile(); int indexPosition(char); char getEncodeChar(int); char getDecodeChar(int); void getWriteFileName(char *str); void getReadFileName(char *str); char alpha[26] = "abcdefghijklmnopqrstuvwxyz"; char filename[14]; char readname[14]; int option; FILE *fp; void main() { clrscr(); printf(" Select any of the option from below."); printf(" 1. Create Encode File"); printf(" 2. Reade Encode File "); scanf("%d", &option); fflush(NULL); if( option == 1) getWriteFileName(filename); elseif( option == 2) { getReadFileName(readname); decodeFile(); } getch(); } void entryData() { char chr; char prevchr; int index=-1; prevchr = chr; printf(" Just type '::' to terminate typing. Start typing "); fflush(NULL); while(1) { scanf("%c", &chr); chr = tolower(chr); if( chr == ':') if( prevchr == chr) break; if( isalpha(chr) ) { index = indexPosition(chr); chr = getEncodeChar(index); } putc(chr, fp); prevchr = chr; } } void getWriteFileName(char *str) { printf("Enter Output File name maxium 14 character : "); scanf("%s", str); if( ( fp = fopen(str, "wt") ) == NULL ) { fclose(fp); printf(" Invalid file name entered."); } else entryData(); } void getReadFileName(char *str) { printf("Enter Input File name maxium 14 character : "); scanf("%s", str); if( ( fp = fopen(str, "r+t") ) == NULL ) { fclose(fp); printf(" Invalid file name entered."); } } void decodeFile() { char rchar; int index=-1; while( feof(fp) == 0 ) { rchar = getc(fp); if( isalpha(rchar) ) { index = indexPosition(rchar); rchar = getDecodeChar(index); } printf("%c", rchar); } } char getEncodeChar(int index) { int tmp=0; tmp = index + 5; if ( tmp > 25) tmp = tmp - 26; return alpha[tmp]; } char getDecodeChar(int index) { int tmp=0; tmp = index - 5; if ( tmp < 0) tmp = 26 + tmp; return alpha[tmp]; } int indexPosition(char chr) { int count=0; for( ; count < 26; count++) { if ( alpha[count] == chr) break; } return count; } /*******************Input******************************* Select any of the option from below. 1. Create Encode File 2. Reade Encode File 1 Enter Output File name maxium 14 character : output.txt contain of output.txt is ymnx nx jcfruqj tk knqj jshtinsl. : 2 Read Encoded File ******************* OutPut******************************* Enter Input File name maxium 14 character : output.txt this is example of file encoding. : */Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.