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

(Using C++) A company communicates with the world using Internet The company wan

ID: 3838675 • Letter: #

Question

(Using C++)

A company communicates with the world using Internet The company wants data to be transmitted securely in the form of 4-digit integers. Write a program for the company that encrypts and decrypts their data by creating two functions, encrypt and decrypt(). The user may choose to encrypt or decrypt the integer based on his/her choice. Please note that the function must not return anything but still the main() function will get the resulted number. Encryption process will be as follows: Replace each digit of the integer input by (digit 7) modulus 10; whereas the decrypted integer can be obtained by reversing the encryption process, i.e. (digit 3) modulus 10.

Explanation / Answer

#include<iostream>

using namespace std;

void encrypt(int & e, int d) {
   int n = 1000;
   e = 0;
   while (n > 0) {
       e = e *10 + (((d/n)+7) % 10);
       d = d % n;
       n = n / 10;
   }
}

void decrypt(int e, int & d) {
   int n = 1000;
   d = 0;
   while (n > 0) {
       d = d *10 + (((e/n)+3) % 10);
       e = e % n;
       n = n / 10;
   }
}

int main() {
   int n;
   char ch;
   cout << "Enter a 4-digit integer followed by 'E' for Encryption and 'D' for Decryption" << endl;
   cin >> n;
   cin >> ch;
   if (ch == 'E') {
       int e;
       encrypt(e, n);
       cout << "Your choice was E and the resulted nunber is " << e << endl;
   }
   else if (ch == 'D') {
       int d;
       decrypt(n, d);
       cout << "Your choice was D and the resulted nunber is " << d << endl;
   }
}

Here you go champ. Hope this helps you. Let me know if you need any guidance