In: Computer Science
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
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