CAN ANYBODY PLEASE HELP ME AND ANSWER THIS PROGRAM WITHIN THE NEXT HOUR???!! THI
ID: 3831712 • Letter: C
Question
CAN ANYBODY PLEASE HELP ME AND ANSWER THIS PROGRAM WITHIN THE NEXT HOUR???!! THIS IS MY PROGRAMMING PRACTICE FINAL EXAM!! PLEASE I NEED HELP! ANYONE!! ANYONE!!! ANYBODY!!
rammi Exam ersion B (3) page encrypted and put in the fle "secret.trt'. For example, this file might look like the following Tli xbpjr j zwev mrve ufxapo yfob dro xmlk qbt. A qxge wb jo wkh hayn. was encrypted in the following manner: The original message was inputted word by word. the n in the file, each small in the word was urotated up plus the length of the word, with (An will follow) Any other characters in the word were left as is, ie, copied from the original message into the encrypted message Your job, as master spy, is to write a decryptor program which decrypts the secret message and outputs the "plaintext" (decoded) result! Specifically, you should ntput the encrypted message secret.txtr) word by word, undo the encryption, and output the result. Ofcourse, you should do this by taking the smalllettersin the n th word and rotating them down (by n plus the word's length) with wraparound. (Again, other characters in the word should be left alone.) For example, in our illustration above, the first encrypted word is "Tli'. The Tr needs no decryption. The "l' should be rotated down by 1+3 4 (we are in the first word, and word length 3, so "l' maps to "h, and similarly the 'i' maps to "e [That is, the first word in the decrypted message is "The".] As another example, the last (27 th) encrypted word is "hayn.", which has length 5. (The period, as non-white-space, is part ofthe word you need not worry about thisl Therefore, to decrypt, each small letter in the word would be rotated down by 27+532 (which 6 with wraparound), that is, 'h' mapsto b', 'a maps (with wraparound to 'u', 'y' maps to 's', and 'n' maps to 'h'. (The ending period is left as is.) So the last word in the decrypted message is "bush." (a). Recell that in C++ you can do arithmetic on characters (b. You will iefinitely find the mod function usefu (o. For C-style string declaration purposes, you can assume the size of any word in the secret txt" file isExplanation / Answer
Here is the code for the question. Please do rate the answer if it helped. Thank you very much
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
//decrypts a input word which at position wordNum in the file.
void decrypt(int wordNum, char *input, char *output)
{
int downsize;
downsize = ( wordNum + strlen(input) ) % 26 ; //wraparound the 26 letters of alphabet
int ch, i, remaining;
for( i =0; input[i]!= '' ; i++)
{
if(input[i]>='a' && input[i]<='z') //only characters in range a-z need to be decrypted
{
ch = input[i] - downsize;
if(ch < 'a') //if the resulting character is out of the character range a-z, bring it back into the range
{
remaining = 'a'-ch-1 ;
ch = 'z' - remaining;
}
output[i] = ch;
}
else
output[i] = input[i]; //just copy characters other than a-z
}
output[i] = '';
}
int main()
{
ifstream infile("secret.txt");
if(!infile)
{
cout<<"Could not read input file secret.txt"<<endl;
return 1;
}
char encrypted[45], decrypted[45];
int wordNum = 1;
//read each word
while(infile >> encrypted)
{
decrypt(wordNum, encrypted, decrypted);
if(wordNum % 6 == 0) //for every 6th word , outtput a newline
cout<<endl;
cout<<decrypted<<" ";
wordNum++;
}
infile.close();
return 0;
}
sample input file
Tli xbpjr jzwev mve ufxapo yfob dro xmlk qbt. A qxgs wb jxu zsfv cwpdano fg ikoo, wpo u spmmjoh stone gq yqtvj uxp jo wkh hayn.
sample output
The quick brown fox jumped
over the lazy dog. A bird
in the hand gathers no moss,
but a rolling stone is worth
two in the bush.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.