C or C++ ONLY PLEASE
Title
Functions
Functional Requirements
Write a program that receives a 5-digit integer number from user and perform encryption and decryption on it as follows:
Encryption: Every single digit will be increased by 3. For example 1 goes to 4, 6 goes to 9, 7 goes to 0, 8 goes to 1, etc
Decryption: Every single digit will be decreased by 3. For example, 9 goes to 6, 3 goes to 0, 2 goes to 9, 1 goes to 8, etc.
Structure of your program will look like this:
int data;
void Encrypt() {
//your code here
}
void Decrypt() {
//your code here
}
void main() {
//get data from user
//encrypt
Encrypt();
//save and print encrypted value here
//decrypt
Decrypt();
//save and print decrypted value here
//compare decrypted data and original data to make sure they are ok
//print a message saying encryption was successful or not
}
Expert Answer
int data;
void Encrypt();
void Decrypt();
void main() {
//get data from user
printf(“Enter the 5 digit number to be encryptedn”);
scanf(“%d”,&data);
//encrypt
Encrypt();
//save and print encrypted value here
int encryptedData=data;
printf(“Encrypted value: %dn”,data);
//decrypt
Decrypt();
//save and print decrypted value here
int decryptedData=data;
printf(“Decrypted value: %dn”,data);
//compare decrypted data and original data to make sure they are ok
//print a message saying encryption was successful or not
if(encryptedData==decryptedData){
printf(“Encryption successful”);
}else{
printf(“Encryption not successfull”);
}
}
void Encrypt(){
int temp=0,i;
for(i=0;i<5;i++){
temp=temp*10+(((data%10)+3)%10);
data=data/10;
}
data=0;
for(i=0;i<5;i++){
data=data*10+(temp%10);
temp=temp/10;
}
}
void Decrypt(){
int temp=0,i;
for(i=0;i<5;i++){
int j=(data%10)-3;
if(j<0){
j=j+10;
}
temp=temp*10+j;
data=data/10;
}
data=0;
for(i=0;i<5;i++){
data=data*10+(temp%10);
temp=temp/10;
}
}
OUTPUT: