One of the oldest known encryption methods is the Caesarcipher, attributed to Ju
ID: 3615302 • Letter: O
Question
One of the oldest known encryption methods is the Caesarcipher, attributed to Julius Caesar. The cipher is determined by a"shift amount" s. Each letter in a message is replaced by theletter s positions past it in the alphabet, wrapping around to thefirst letter when the shift goes past the end.In a program, the way to compute the replacement letter for anupper-case letter ch would be
((ch-'A')+s) % 26 + 'A'. For lower-case letters, the replacementwould be ((ch-'a')+s) % 26 + 'a'.
You are to write a program that encrypts a text file using a Caesarcipher. It should encrypt alphabetical characters only, leaving allother characters unchanged. You will prompt for the input file nameand the shift amount using the exact prompts shown below. Theencrypted text will be written to another file whose name is formedby adding .enc to the end of the input file name.
Thus, the shift amount is 3 and the input file contained "Go ahead,make my day", then the output file would contain "Jr dkhdg, pdnh pbgdb".
An example run would look like this:
Enter name of file to be encrypted: message.txt
Enter shift amount (1 – 25): 3
The program will then write the encrypted text to the filemessage.txt.enc.
For the files project, youwill need two variables of type FILE *, one for the input file andone for the output file. And two arrays to hold the filenames.After getting the names of the files from the user, you must openthe input file for input and the output file for output (fopen).Then you use fgetc to input characters from the input file andfputc to put the replacement characters to the output file (onlyalphabetical characters will be replaced). You must somehow detectwhen you run out of characters from the input file. Then make sureto close your files before termination (with fclose). One of the oldest known encryption methods is the Caesarcipher, attributed to Julius Caesar. The cipher is determined by a"shift amount" s. Each letter in a message is replaced by theletter s positions past it in the alphabet, wrapping around to thefirst letter when the shift goes past the end.
In a program, the way to compute the replacement letter for anupper-case letter ch would be
((ch-'A')+s) % 26 + 'A'. For lower-case letters, the replacementwould be ((ch-'a')+s) % 26 + 'a'.
You are to write a program that encrypts a text file using a Caesarcipher. It should encrypt alphabetical characters only, leaving allother characters unchanged. You will prompt for the input file nameand the shift amount using the exact prompts shown below. Theencrypted text will be written to another file whose name is formedby adding .enc to the end of the input file name.
Thus, the shift amount is 3 and the input file contained "Go ahead,make my day", then the output file would contain "Jr dkhdg, pdnh pbgdb".
An example run would look like this:
Enter name of file to be encrypted: message.txt
Enter shift amount (1 – 25): 3
The program will then write the encrypted text to the filemessage.txt.enc.
For the files project, youwill need two variables of type FILE *, one for the input file andone for the output file. And two arrays to hold the filenames.After getting the names of the files from the user, you must openthe input file for input and the output file for output (fopen).Then you use fgetc to input characters from the input file andfputc to put the replacement characters to the output file (onlyalphabetical characters will be replaced). You must somehow detectwhen you run out of characters from the input file. Then make sureto close your files before termination (with fclose).
Explanation / Answer
//hope this will help you. #include #include #include void cipher(char *ch,int s) { if(*ch >='a'&& *ch='A'&& *chRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.