Program reads a line of text and then either performs encryption or decryption,
ID: 3654659 • Letter: P
Question
Program reads a line of text and then either performs encryption or decryption, depending on the ?rst character read. If the ?rst character is $, then you encrypt the rest of the line, and precede your output by the character ?. If the ?rst character is ?, then you are supposed to decrypt the rest of the line, and precede your output by the character $. If the first character is neither a $ nor ?, terminate the program. Use a shift of 3 letters. For example, if input is $To be, or not to be, then output reads ?Wr eh, ru qrw wr eh. Similarly, if input is ?Wkh txlfn eurzq ira mxpsv ryhu wkh odcb grj, then output should read $The quick brown fox jumps over the lazy dog.Explanation / Answer
#include #include void crypt(char *); int main(){ char str[500]={""},temp; int i; printf("Enter a string: "); temp=getchar(); for(i=0;temp!=' ';i++){ str[i]=temp; temp=getchar(); } //printf(" %s",str); if(str[0]=='$'||str[0]=='?'){ crypt(str); printf(" %s",str); } printf(" Press any key to exit..."); getch(); return 0; } void crypt(char * str){ int code=3; if(*str=='?') code*=-1; while(*str!=''){ if(((*str>='A')&&(*str='a')&&(*strRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.