Question

In: Computer Science

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.

 

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 and decrypts 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. Create an Encrypt class to do the encryption, create a decrypt class to do the decryption (convert the encrypted number to its original number)

Your main duty for this assignment is creating an Encrypt class which includes Encrypt.h and Encrypt.cpp, and Decrypt class which includes Decrypt.h and Decrypt.cpp. After finish the tasks you can use CISP.cpp to test the Encrypt and Decrypt classes.

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 this 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. The other Encrypt constructor takes an array of any length and stores the first four digits (0 ~ 3). It encrypts the first four digits, stores the encrypted information, displays a call to this constructor information, and shows the original information and encrypted information. If the inputted first four is less than or equal to 0 the integer is set to 9436.

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

d. A storeData function takes an integer and does not return anything. It stores the last four digits of the passed in integer to the first 4 elements of the private data member, encrypts the data and store them in the last 4 elements of the private data member.

e. A displayEncryptedData function does not accept and return any data. It displays the last four elements of the private data member.

f. A getEncryptedData function does not accept any data. It returns an integer, the 4 digit encrypted integer.

The following is the Decrypt class specification.

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

2. Decrypt class has several public member functions

a. A decrypt constructor takes an integer of any digits and stores the last four digits. It decrypts the last four digits, stores the decrypted information, displays a call to the constructor information, and shows the original and decrypted information. If the inputted number is less than or equal to 0 the integer is set to 1234.

b. Another decrypt constructor takes an integer array of any size and store the array element 0 to 3. It decrypts the 0 ~ 3 elements, stores the decrypted information, displays a call to the constructor, and shows the original and decrypted information. If the inputted number is less than or equal to 0 the integer is set to 1234.

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

d. A storeData function takes an integer and does not return anything. It stores the last four digits of the passed in integer to the last 4 elements of the private data member, decrypts the data and store them in the first 4 elements of the private data member.

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

f. A getDecryptedData function does not accept any data. It returns an integer, the 4 digit decrypted integer.

Solutions

Expert Solution

(1)encrypt.h

class Encrypt{

private:

int digits[8];

public:

Encrypt(int);

Encrypt(int * ,int);

void displayOriginalData();

void storeData(int);

void displayEncryptedData();

int getEncryptedData();

void swap(int & ,int &);

};

(2)encrypt.cpp

#include "encrypt.h"

#include

using namespace std;

Encrypt::Encrypt(int n){

if(n<=0){

digits[0]=9;

digits[1]=4;

digits[2]=3;

digits[3]=6;

}

else{

digits[3]=n%10;

n/=10;

digits[2]=n%10;

n/=10;

digits[1]=n%10;

n/=10;

digits[0]=n%10;

}

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

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

swap(digits[4],digits[6]);

swap(digits[5],digits[7]);

}

Encrypt::Encrypt(int * arr ,int n){

if(n<4 ||(n>=4&&(arr[0]*arr[1]*arr[2]*arr[3])<0)||(n>=4&&arr[0]==0&&arr[1]==0&&arr[2]==0&&arr[3]==0)){

digits[0]=9;

digits[1]=4;

digits[2]=3;

digits[3]=6;

}

else{

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

digits[i]=arr[i];}

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

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

swap(digits[4],digits[6]);

swap(digits[5],digits[7]);

}

void Encrypt::displayOriginalData(){

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

cout<

cout<<"\n";

}

void Encrypt::storeData(int n){

if(n<=0){

digits[0]=9;

digits[1]=4;

digits[2]=3;

digits[3]=6;

}

else{

digits[3]=n%10;

n/=10;

digits[2]=n%10;

n/=10;

digits[1]=n%10;

n/=10;

digits[0]=n%10;

}

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

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

swap(digits[4],digits[6]);

swap(digits[5],digits[7]);

}

void Encrypt::displayEncryptedData(){

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

cout<

cout<<"\n";

}

int Encrypt::getEncryptedData(){

int num=0;

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

num*=10;

num+=digits[i];

}

return num;

}

void Encrypt::swap(int &a ,int &b){

int temp=a;

a=b;

b=temp;

}

(3)decrypt.h

class Decrypt{

private:

int digits[8];

public:

Decrypt(int);

Decrypt(int * ,int);

void displayOriginalData();

void storeData(int);

void displayDecryptedData();

int getDecryptedData();

void swap(int & ,int &);

};

(4)decrypt.cpp

#include "decrypt.h"

#include

using namespace std;

Decrypt::Decrypt(int n){

if(n<=0){

digits[0]=1;

digits[1]=2;

digits[2]=3;

digits[3]=4;

}

else{

digits[3]=n%10;

n/=10;

digits[2]=n%10;

n/=10;

digits[1]=n%10;

n/=10;

digits[0]=n%10;

}

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

if(digits[i]>=0 &&digits[i]<=6)digits[i+4]=3+digits[i];

else digits[i+4]=digits[i]-7;}

swap(digits[4],digits[6]);

swap(digits[5],digits[7]);

}

Decrypt::Decrypt(int * arr,int n){

if(n<4 ||(n>=4&&(arr[0]*arr[1]*arr[2]*arr[3])<0)||(n>=4&&arr[0]==0&&arr[1]==0&&arr[2]==0&&arr[3]==0)){

digits[0]=1;

digits[1]=2;

digits[2]=3;

digits[3]=4;

}

else{

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

digits[i]=arr[i];}

  

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

if(digits[i]>=0 &&digits[i]<=6)digits[i+4]=3+digits[i];

else digits[i+4]=digits[i]-7;}

swap(digits[4],digits[6]);

swap(digits[5],digits[7]);

}

void Decrypt::displayOriginalData(){

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

cout<

cout<<"\n";

}

void Decrypt::storeData(int n){

if(n<=0){

digits[0]=1;

digits[1]=2;

digits[2]=3;

digits[3]=4;

}

else{

digits[3]=n%10;

n/=10;

digits[2]=n%10;

n/=10;

digits[1]=n%10;

n/=10;

digits[0]=n%10;

}

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

if(digits[i]>=0 &&digits[i]<=6)digits[i+4]=3+digits[i];

else digits[i+4]=digits[i]-7;}

swap(digits[4],digits[6]);

swap(digits[5],digits[7]);

}

void Decrypt::displayDecryptedData(){

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

cout<

cout<<"\n";

}

int Decrypt::getDecryptedData(){

int num=0;

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

num*=10;

num+=digits[i];

}

return num;

}

void Decrypt::swap(int &a ,int &b){

int temp=a;

a=b;

b=temp;

}

(5)main.cpp

#include "encrypt.cpp"

#include "decrypt.cpp"

int main(){

int num = 23456;

Encrypt en(num);

en.displayOriginalData();

en.displayEncryptedData();

Decrypt de(en.getEncryptedData());

de.displayOriginalData();

de.displayDecryptedData();

}

//sample output


Related Solutions

A company wants to transmit data over the telephone but is concerned that its phones could be tapped
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...
A company is concerned about the quality of production in its four plants. To test the...
A company is concerned about the quality of production in its four plants. To test the quality, managers take measurements of valve openings (the dependent variable) by one machine operator (the independent variable) in each plant. The results are stacked in columns by operator 1 through 4 below. 6.33       6.26     6.44    6.29 6.26       6.36     6.38    6.23 6.31       6.23     6.58    6.19 6.29       6.27     6.54    6.21 6.4         6.19     6.56                6.5       6.34                6.19     6.58                6.22 Please provide the five step...
Enter your PIN: The technology company DataGenetics suggests that 17.8 % of all four-digit personal identification...
Enter your PIN: The technology company DataGenetics suggests that 17.8 % of all four-digit personal identification numbers, or PIN codes, have a repeating digits format such as 2525. Assuming this to be true, if the PIN codes of nine people are selected at random, what is the probability that at least one of them will have repeating digits? Round your answer to four decimal places. The probability that at least one of the codes will have repeating digits is
A company that wants to send data over the Internet has asked you to write a...
A company that wants to send data over the Internet has asked you to write a program that will encrypt it so that it may be transmitted more securely. All the data is transmitted as four-digit integers. Your application should read a four-digit integer entered by the user and encrypt it as follows: Replace each digit with the result of adding 7 to the digit and getting the remainder after dividing the new value by 10. Then swap the first...
A company that wants to send data over the Internet has asked you to write a...
A company that wants to send data over the Internet has asked you to write a program that will encrypt it so that it may be transmitted more securely. All the data is transmitted as four-digit integers. Your application should read a four-digit integer entered by the user and encrypt it as follows: Replace each digit with the result of adding 7 to the digit and getting the remainder after dividing the new value by 10. Then swap the first...
1. A company that wants to send data over the Internet will use an encryption program...
1. A company that wants to send data over the Internet will use an encryption program to ensure data security. All data will be transmitted as four-digit integers. The application should read a four-digit integer entered by the user and encrypt it as follows:  Replace each digit with the remainder of the new value divided by 10 by adding 6 to the digit. Then replace the number in the first digit with the third, and the number in the...
1) A company that wants to send data over the Internet will use an encryption program...
1) A company that wants to send data over the Internet will use an encryption program to ensure data security. All data will be transmitted as four-digit integers. The application should read a four-digit integer entered by the user and encrypt it as follows:  Replace each digit with the remainder of the new value divided by 10 by adding 6 to the digit. Then replace the number in the first digit with the third, and the number in the...
1. A company that wants to send data over the Internet will use an encryption program...
1. A company that wants to send data over the Internet will use an encryption program to ensure data security. All data will be transmitted as four-digit integers. The application should read a four-digit integer entered by the user and encrypt it as follows:  Replace each digit with the remainder of the new value divided by 10 by adding 6 to the digit. Then replace the number in the first digit with the third, and the number in the...
A lumber company transports its logs by floating them over a river. It wants to find...
A lumber company transports its logs by floating them over a river. It wants to find the mean time for a log to travel down to the factory. Measuring the time for 25 logs, it finds the mean time to be 65 minutes, with a standard deviation of 8 minutes. Construct a 95% confidence interval for the mean travel time.
An insurance company provides four sequential services to its customers. Over the last year, the reliability...
An insurance company provides four sequential services to its customers. Over the last year, the reliability of each of these services was 94%, 97%, 95%, and 91%. What is their overall reliability? Question 19 options: a. 0.9425 b. 0.9500 c. 0.9999 b. 0.7883
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT