Question

In: Computer Science

The Encrypt class has an integer private data member 8 element array named digits. The first four elements (0 ~ 3) are to store the original 4 digits integer and the next four (4 ~ 7) are to store the encrypted data

C++ Please Modify the code and create a new header file

A company wants to transmit data over the telephone, but is concerned that its phones could be tapped. All of the data are transmitted as four-digit integers. The company has asked you to write a program that encrypts the data so that it can be transmitted more securely. Your program should read a four-digit integer and encrypt it as follows: Replace each digit by (the sum of that digit plus 7) modulus 10. Then, swap the first digit with the third, swap the second digit with the fourth and print the encrypted integer. Your main duty for this assignment is creating an Encrypt class which includes Encrypt.h and Encrypt.cpp. After finishing the task you can use CISP400V10A2.cpp to test the Encrypt class.

The following is the Encrypt class specification.

1. The Encrypt class has an integer private data member 8 element array named digits. The first four elements (0 ~ 3) are to store the original 4 digits integer and the next four (4 ~ 7) are to store the encrypted data.

2. Encrypt class has several public member functions

a. An Encrypt constructor takes an integer of any digits and stores the last four digits. It encrypts the last four digits, stores the encrypted information, displays a call to the constructor information, and shows the original information and encrypted information. If the inputted number is less than or equal to 0 the integer is set to 9436.

b. A displayOriginalData function does not accept and return any data. It displays the first four elements of the private data member.

/ CISP400V10A2.cpp

// Test program for class Encrypt.

#include "Encrypt.h" // include definition of class Encrypt

#include

#include

using namespace std;

int main()

{

Encrypt app1(0), app2(40), app3(4560), app4(6145698),app5(-6); // create Encrypt objects  

  

cout<<endl<< "Reset the app1's data to 100." << endl;// display the reset of app1.

app1.storeData(100);// call app1's storeData function

app1.displayOriginalData();//display the app1's current original data.

app1.displayEncryptedData();// display the app1's current encrypted data.

cout << endl;//Jump to the next line

system("PAUSE");

return 0; // indicate successful termination

} // end main

Solutions

Expert Solution

Hi, please go threw code and output.

CISP400V10A2.cpp

// CISP400V10A2.cpp

// Test program for class Encrypt.

#include "Encrypt.h" // include definition of class Encrypt

#include

#include

using namespace std;

int main()

{

Encrypt app1(0), app2(40), app3(4560), app4(6145698),app5(-6); // create Encrypt objects

cout<

  

app1.storeData(100);// call app1's storeData function

app1.displayOriginalData();//display the app1's current original data.

app1.displayEncryptedData();// display the app1's current encrypted data.

cout << endl;//Jump to the next line

system("PAUSE");

return 0; // indicate successful termination

} // end main

Encrypt.cpp

#include

#include "Encrypt.h"

using namespace std;

Encrypt::Encrypt(int data){

cout<<"** The default constructor is called "<

cout<<"and the passed in number is "<

cout<

if(data <= 0){

cout<<"XXX the input number is less than or equal to 0."<

cout<<"The number is reset to 9436. XXX"<

data = 9436;

}

for(int i=3; i>=0; i--){

digits[i] = data%10;

data = data/10;

}

for(int i=0; i<4; i++){

int digit = digits[i];

digits[i+4] = (digit + 7) % 10;

}

// Now swap 1st and 3rd and 2nd and fourthof encrypted digit

int temp = digits[4];

digits[4] = digits[6];

digits[6] = temp;

temp = digits[5];

digits[5] = digits[7];

digits[7] = temp;

cout<<"The original data is ";

for(int i=0; i<4; i++){

cout<

}

cout<<"."<

for(int i=4; i<8; i++){

cout<

}

cout<

}

void Encrypt::displayOriginalData(){

cout<<"The original data is ";

for(int i=0; i<4; i++){

cout<

}

cout<

}

void Encrypt::displayEncryptedData (){

cout<<"The encrypted data is ";

for(int i=4; i<8; i++){

cout<

}

}

void Encrypt::storeData(int data){

for(int i=3; i>=0; i--){

digits[i] = data%10;

data = data/10;

}

for(int i=0; i<4; i++){

int digit = digits[i];

digits[i+4] = (digit + 7) % 10;

}

// Now swap 1st and 3rd and 2nd and fourthof encrypted digit

int temp = digits[4];

digits[4] = digits[6];

digits[6] = temp;

temp = digits[5];

digits[5] = digits[7];

digits[7] = temp;

}

Encrypt.h

#ifndef ENCRYPT_H

#define ENCRYPT_H

class Encrypt{

private:

int digits[8];

public:

Encrypt(int data);

void displayOriginalData();

void storeData(int data);

void displayEncryptedData ();

};

#endif


Related Solutions

Hexadecimal digits are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C,...
Hexadecimal digits are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, and F. How many hexadecimal strings of length twelve have five A’s and five B’s? How many hexadecimal strings of length twelve have at most three E’s? How many hexadecimal strings of length twelve have exactly three A’s and at least two B’s? How many hexadecimal strings of length twelve have exactly two A’s and exactly two B’s, so that the two...
DATA 3 8 2 15 2 2 0 0 4 5 2 7 0 1 5...
DATA 3 8 2 15 2 2 0 0 4 5 2 7 0 1 5 3 0 2 5 4 1 6 9 5 3 1 2 10 6 1 1 2 1 19 6 6 6 7 0 4 1 1 1 0 1 9 2 2 2 1 16 10 10 5 2 3 1 4 4 4 3 6 2 8 5 2 7 1 6 4 0 3 1 1 1 Background: A group of...
Find regression line for the data X 0   1   2   3    4   5   6   7  8          &nbsp
Find regression line for the data X 0   1   2   3    4   5   6   7  8               [3 MARKS] Y 11 21 31 41 51 61 71 81 91 b. X  0   2   4   6   8  10                            [3 MARKS]       Y  12 15 17 18 20 22
Given the matrix 7 7 -4 12 -5 A = 9 10 2 6 13 8 11 15 4 1 3. a. Sort each column and store the result in an array B.
Given the matrix a. Sort each column and store the result in an array B.b. Sort each row and store the result in an array C.c. Add each column and store the result in an array D.d. Add each row and store the result in an array E.  
A set of data has the following coordinates t 0 1 3 4 7 y 2...
A set of data has the following coordinates t 0 1 3 4 7 y 2 4 5 7 10 a) Find the least-squares fit to this data by a linear function of t (that is, find constants c1,c0 so that y(t) = c1t + c0 is the best linear fit to this set of data). b) Find the equation of the best quadratic fit to the same set of data. Then find the equation of the polynomial of smallest...
Input Data Month 0 1 2 3 4 5 6 7 8 9 10 11 12...
Input Data Month 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 Revenue $             -   $            -   $            -   $        -   $        -   $         -   $    2,500 $    2,875 $    3,306 $    3,802 $    4,373 $    5,028 $    5,783 $    6,650 $    7,648 $      8,795 $   10,114 $   11,631 $   13,376 $   15,382 $   17,689 $   20,343 $   23,394 $   26,903 Monthly Revenue Growth...
Input Data Month 0 1 2 3 4 5 6 7 8 9 10 11 12...
Input Data Month 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 Revenue $             -   $            -   $            -   $        -   $        -   $         -   $    2,500 $    2,875 $    3,306 $    3,802 $    4,373 $    5,028 $    5,783 $    6,650 $    7,648 $      8,795 $   10,114 $   11,631 $   13,376 $   15,382 $   17,689 $   20,343 $   23,394 $   26,903 Monthly Revenue Growth...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT