0% found this document useful (0 votes)
24 views3 pages

#Include #Include Using Namespace Void Int Void Int Void Double Double Int Int Do

The document contains code for encrypting and decrypting 4-digit numbers. It includes functions for encryption, decryption, and swapping values. The encryption function takes a 4-digit number as input, performs mathematical operations on each digit, and swaps the 1st and 3rd and 2nd and 4th digits to produce the encrypted number. The decryption function takes the encrypted number, performs inverse mathematical operations on each digit, and swaps the digits back to their original positions to decrypt the number.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views3 pages

#Include #Include Using Namespace Void Int Void Int Void Double Double Int Int Do

The document contains code for encrypting and decrypting 4-digit numbers. It includes functions for encryption, decryption, and swapping values. The encryption function takes a 4-digit number as input, performs mathematical operations on each digit, and swaps the 1st and 3rd and 2nd and 4th digits to produce the encrypted number. The decryption function takes the encrypted number, performs inverse mathematical operations on each digit, and swaps the digits back to their original positions to decrypt the number.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

//question 5(b)

#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;
}

You might also like