Source code
#include <stdio.h>
int encrypt( int num){
int n1 = num / 1000;
int n2 = (num % 1000) / 100;
int n3 = (num % 100) / 10;
int n4 = num % 10;
n1 = (n1 + 5) % 8;
n2 = (n2 + 5) % 8;
n3 = (n3 + 5) % 8;
n4 = (n4 + 5) % 8;
return (n3 * 1000 + n4 * 100 + n1 * 10 + n2);
}
int decrypt( int num)
{
int n1 = num / 1000;
int n2 = (num % 1000) / 100;
int n3 = (num % 100) / 10;
int n4 = num % 10;
n1 = (n1 + 3) % 8;
n2 = (n2 + 3) % 8;
n3 = (n3 + 3) % 8;
n4 = (n4 + 3) % 8;
return (n3 * 1000 + n4 * 100 + n1 * 10 + n2);
}
int main()
{
int num;
printf("Enter a four digit number: ");
scanf("%d",&num);
printf("The number after encryption is: %d\n",encrypt(num));
printf("The encrypted number after decryption is: %d",decrypt(encrypt(num)));
}
Output
Comments
Leave a comment