Can someone help me with this? This is part of my first assignment.
I am quite new to programming.

A company wants to transmit data over the telephone, but they are concerned that their phones are tapped. All of their data are transmitted as four-digit integers. They wanted you to write a program that encrypts their data so that it can be transmitted securely. Your program should read a four-digit integer and encrypts it as follows : Add 7 to each digit and modulus 10. Then swap the first with the third and the second with the fourth. Lastly, display the data before and after encryption.

This requires to have a PAC Chart, IPO chart, Algorithm, Flowchart, Data Dictionary, C++ code

## All 3 Replies

Think about what you're going to code.

Identify the first thing your code will do. For example, you might decide to start by getting a four digit number from the user. Code that. Code as far as you can and then come back with your code and ask us about what you're stuck on.

Someone gave me the code for this question 3 days ago, but he did not put anything for me to input. Here is the code:

``````#include "stdafx.h"
#include <iostream>
#include <cmath>

using namespace std;

void Swap(int& a, int& b)
{
int temp = a;
a = b;
b = temp;
}

void encrypt(int& num)
{
int ary[4];
for(int i = 3; i >= 0; i--)
{
ary[i] = (int)(num / pow(10,i)) % 10;
}
for(int i = 0; i < 4; i++)
{
ary[i] += 7;
ary[i] %= 10;
}
Swap(ary[0],ary[2]);
Swap(ary[1],ary[3]);
num = 0;
for(int i = 0; i < 4; i++)
num += ary[i] * pow(10,i);
}

void decrypt(int& num)
{
int ary[4];
for(int i = 3; i >= 0; i--)
{
ary[i] = (int)(num / pow(10,i)) % 10;
}
for(int i = 0; i < 4; i++)
{
ary[i] += 3;
ary[i] %= 10;
}
Swap(ary[0],ary[2]);
Swap(ary[1],ary[3]);
num = 0;
for(int i = 0; i < 4; i++)
num += ary[i] * pow(10,i);
}

int main()
{
int data = 1234;
cout << "Start: " << data << endl;
encrypt(data);
cout << "Encrypted: " << data << endl;
decrypt(data);
cout << "Decrypted: " << data << endl;

system("pause");

return 0;
}
``````

Do you also have a PAC chart, IPO chart, Algorithm and Flowchart?

The algorithm is in the question. I've no idea what a PAC chart or IPO chart are.

Perhaps you should write your own code instead of copying someone else's. That way, you might be able to write code to take input from the user.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.