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

A company wants to transmit data over the telephone, but is concerned that its p

ID: 3787879 • Letter: A

Question

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.

c. 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.

d. A displayEncryptedData function does not accept and return any data. It displays the last 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<   
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

They're all the requirement of this program. Basically, I just want to know how to pass the integer value from app1, app2, app3, etc. into the class Encrypt class. All I have learned so far is about the construct and some function about "get and set". The first program practiced on using function set and get. This program does not provide any get and set function, I also not allow to modify the file CISP400V10A2. For example, app2{40} => app2.getValue(), then it will pass the integer 40 into a private variable in the class. However, this one is a little different because there aren't any get and set. Also, there only app1. According to one of the file .exe, it shows that the value in app2, app3, app4, and app5 also pass into the class without using these app variables in the CISP400V10A2.cpp.

The number is reset to 9436. XXX The original data is 9 4 3 6 The encrypted data is 0 3 6 1. The default constructor is called and the passed in number is 40 The original data is e 0 4 0 The encrypted data is 1 7 7 7. The default constructor is called and the passed in number is 4560. The original data is 4 560. The encrypted data is 3 7 1 2. The default constructor is called and the passed in number is 6145698 The original data is 569 8. The encrypted data is 6 5 2 3. The default constructor is called and the passed in number is -6.**

Explanation / Answer

The following example shows how to pass a interger through the reference when the function is defined through constructor function. As you have mentioned you dont want to use get or set function in that case you can make use of this method.

#include <iostream>
using namespace std;

class c
{
public:
int value;
c(const int& arg)

void print();

;
};

// this is a member function of c
      c::c(const int& arg)
   {
    value=arg;
}

void c::print()

{ cout << "value= "<<value<<endl; }

int main()
{
int i;
i=6;
c test_class(i);
test_class.print();
cout << "i=" << i << endl;
}

//below i give a sample program to read and display the value... THE ENCRYPTION FUNCTION WRITTEN IS NOT ACCORDING TO YOUR REQUIREMENT AS YOU HAVE NOT MENTIONED YOU NEED THAT..SO PLEASE DO EDIT IT BEFORE RUN..

ENCRYPT.h

#ifndef ENCRYPT_H
#define ENCRYPT_H


class ENCRYPT
{
    private:
        int value;
      
        int key;
        int num;
        int sum;
    public:
        ENCRYPT(int &arg);
        void displayORIGINALDATA();
        int Encryption();
        void displayENCRYPTEDDATA(int &ar);
      
};

ENCRYPT.cpp

#include <iostream>
#include <conio.h>
#include "ENCRYPT.h"

using namespace std;

ENCRYPT::ENCRYPT(const int& arg)
   {
    value=arg ;
}


void ENCRYPT::displayORIGINALDATA()
{
    cout << "Password Encryption And Decryption"
          cout << "arg=" << value << endl
                  
}

int ENCRYPT::Encryption()
{
    cout << " Please Choose A Secret ID For Your Password : ";
    cin >> Rid;
  
    key=strlen(value);
    num = value;
    if(key != 4)
        {   cout << " Password Must be 4 digits ";    }
    else
    {
            while (num != 0)

    {

        sum = sum + num % 10;

        value = num / 10;

    }} return num;
  
}

void ENCRYPT::displayENCRYPTEDDATA(int &ar)
{
    cout << " encrypted data is " << num ;
}

main.cpp

#include <iostream>
#include <conio.h>
#include <windows.h>
#include "ENCRYPT.h"

using namespace std;

int main()
{

cout << " Enter Password For Encryption. 4 DIGITS ";
    cin >> UString;
  
ENCRYPT a1(UString);
     a1.displayORIGINALDATA();
    enc= a1.Encryption();
    a1.display.ENCRYPTEDDATA(enc);
  
    return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote