Encryption A company wants to transmit data over the telepho

Encryption

A company wants to transmit data over the telephone, but they are concerned that their phones may be tapped. All of their data is transmitted as four-digit integers. They have asked you to write a program that encrypts their data so that it may 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. Write a separate program that inputs and encrypted four-digit integer, and decrypts it to form the original number.

Solution

#include<iostream>
#include<algorithm>
using namespace std;
//program for encryption
void Encrypt(int a[]){
for(int i=0;i<4;i++)
{
a[i]=(a[i]+7)%10;
}
swap(a[0],a[2]);
swap(a[1],a[3]);
return ;

}
//program for decryption
void Decrypts(int a[]){
swap(a[0],a[2]);
swap(a[1],a[3]);
for(int i=0;i<4;i++){
a[i]=a[i]+3;
if(a[i]>=10)
a[i]=a[i]-10;
}
return;
}
//Driver Program
int main()
{
int n,i=0;
cin>>n;
int a[4]={0};
while(n!=0){
a[3-i]=n%10;
n=n/10;i++;
}
Encrypt(a);//Encrypt Function
cout<<\"Encrypted Number is :\";
for(int i=0;i<4;i++)
{
cout<<a[i];
}
cout<<endl;
Decrypts(a);//Decrypt Function
cout<<\"Decrypted Number is :\";
for(int i=0;i<4;i++)
{
cout<<a[i];
}

return 0;

}

Encryption A company wants to transmit data over the telephone, but they are concerned that their phones may be tapped. All of their data is transmitted as four
Encryption A company wants to transmit data over the telephone, but they are concerned that their phones may be tapped. All of their data is transmitted as four

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site