Question: I Need help with my code. My algorithm seems to be able to work when doing the encryption. Except, only for the first one. I

I  I Need help with my code. My algorithm seems to be

able to work when doing the encryption. Except, only for the first

Need help with my code. My algorithm seems to be able to work when doing the encryption. Except, only for the first one. I think there is something wrong when i input from the file and my if statements. Please can you help me solve this problem.

CODE:

#include #include

using namespace std;

void editDigits(int number, int storageArray[], ofstream &outData, int &i) { int n = 1;

while(number>=10) { n = n*10; }

while(n!=0) { int digit = number; storageArray[i] = (digit+8)%10; number = number%n; i = i + 1; n=n/10; } }

void swapDigits(int number,int storageArray[], ofstream &outData) { int tempArray[4] = {0,0,0,0};

tempArray[0] = storageArray[0]; tempArray[1] = storageArray[2]; tempArray[2] = storageArray[1]; tempArray[3] = storageArray[3];

storageArray[0] = tempArray[1]; storageArray[2] = tempArray[0]; storageArray[1] = tempArray[3]; storageArray[3] = tempArray[2];

outData

}

int main() { ifstream inData; inData.open("input.txt"); ofstream outData; outData.open("output.txt");

int number = 0; int storageArray[100]; char unknownoperation; int i = 0;

while (!inData.eof()) {

inData >> unknownoperation >> number;

if (unknownoperation == 'e') { editDigits(number,storageArray,outData,i); if (i>5) { outData

else if (unknownoperation == 'E') { editDigits(number,storageArray,outData,i); if (i>5) { outData

} else { outData

}

return 0; }

You are required to implement a simple encryption algorithm that operates on five-digit integer values. The encryption algorithm is: . Replace each digit by (the sum of that digit plus 8) modulus 10. . Then, swap the first digit with the third. Lastly, swap the second digit with the fourtlh . The resulting five-digit number is the encrypted value You are required to write a computer programme in C++ that reads in a list of operations and numbers from a file and writes the results to an output file

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!