Professional Documents
Culture Documents
#Include #Include Using Namespace Void Int Void Int Void Double Double Int Int Do
#Include #Include Using Namespace Void Int Void Int Void Double Double Int Int Do
#Include #Include Using Namespace Void Int Void Int Void Double Double Int Int Do
#include<iostream>
#include<cmath>
using namespace std;
void encryption(int);
void decryption(int);
void swap(double &,double &);
int main()
{
int choice;
do{
cout<<"1-Encryption"<<endl
<<"2-Decryption"<<endl
<<"3-Exit"<<endl;
cin>>choice;
if(choice==1)
encryption(choice);
else if(choice==2)
decryption(choice);
}while(choice<3);
cout<<"Thanks for trying!"<<endl;
system("pause");
return 0;
}
void encryption(int) //int is the choice value 1
{
const int arraysize = 4;
int a[arraysize],input1;
cout<<"Enter your original 4-digit numbers :";
cin>>input1;
for(int i=3; i>-1; i--)
//for(int i=0; i<4; i++)
{
a[i] = input1%10;
input1 = input1/10;
}
cout<<a[0]<<a[1]<<a[2]<<a[3]<<endl;
for(int i=0; i<4; i++)
{
a[i] = (a[i]*3)%10;
}
swap(a[0],a[2]);
swap(a[1],a[3]);
cout<<"Your encrypted number is : "
<<a[0]<<a[1]<<a[2]<<a[3]
<<endl;
}
void decryption(int)
{
const int arraysize = 4;
int a[arraysize],input2;
cout<<"Enter your 4-digit encrypted numbers :";
cin>>input2;
for(int i=3; i>-1; i--)
//for(int i=0; i<4; i++)
{
a[i] = (input2)%10;
input2 = (input2)/10;
}
cout<<a[0]<<a[1]<<a[2]<<a[3]<<endl;
for(int i=0; i<4; i++)
{
a[i] = ( a[i]*7) % 10;
}
swap(a[0],a[2]);
swap(a[1],a[3]);
cout<<"Your encrypted number is : "
<<a[0]<<a[1]<<a[2]<<a[3]
<<endl;
}