Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

how would I write a c++ program that would decrypt a program and output it\'s pl

ID: 3770723 • Letter: H

Question

how would I write a c++ program that would decrypt a program and output it's plain text. . The encrypted file ("secret.txt") contains :::    Tli xbpjr jzwev mve ufxapo yfabo dro xmlk gbt. A qxgs wb jxu zsfv cwpdano fg ikoo, wpo u spmmjoh stone gq yqtvj uxp jo wkh hayn.

which should read:: 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.

The first word encryption 'tli'... the t needs no decryption. The I should be rotated down 1+3=4 ( we are on the first Word and the word has 3 letters. ) so where ever the l is in the alphabet. go back 4 letters.

Explanation / Answer

The original secret message needs some correction like "over" has 4 letters but its secret counterpart "yfabo" has 5 letters. further the secret message of gbt is not coming dog, insead secret message of qbt is coming dog.

Copy paste the line in the comment below in "secret.txt" and the program works just fine.

/*
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.
*/

#include <iostream>
#include <string>
#include <fstream>

using namespace std;

int main() {

ifstream infile;

infile.open("secret.txt");
if (!infile.is_open()) {
cerr<<"cannot open this file";
}

int pos_word = 1,i,down,asci;
int count = 0;
string word;

while(infile>>word)
{
count = word.size();
cout<<endl<<word<<" ";
for(i=0;i<count;i++)
{
if((pos_word==1&&i==0)||!(word[i]>='a'&&word[i]<='z'))
cout<<word[i];
else
{
down = (pos_word + count)%26;
asci = int(word[i]);
if( (asci-down) < int('a'))
{
down = down - (asci - int('a'));
asci = int('z') - down + 1;
}else
asci -= down;

cout<<char(asci);
}
}
pos_word++;
}
cout<<endl;
return 1;
}