Answer to Question #29842 in C++ for Sean

Question #29842
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.
1
Expert's answer
2013-06-03T10:45:53-0400
#include <cstdlib>
#include <iostream>

using namespace std;

int encrypt(int a)
{
if(a<0) a=0-a;
int dig1,dig2,dig3,dig4;
dig4=((a%10)+7)%10;
a/=10;
dig3=((a%10)+7)%10;
a/=10;
dig2=((a%10)+7)%10;
a/=10;
dig1=((a%10)+7)%10;
a=dig3*1000+dig4*100+dig1*10+dig2;
return a;
}

int main()
{
int n;
cin>>n;
cout<<"Before encryption: "<<n<<endl;
int m=encrypt(n);
if(n<0) m=0-m;
cout<<"After encryption: "<<m<<endl;
system("pause");
return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS