hey everyone
this board sounds great

i have a question that has been bothering me for a while
and it due next saterday

the question is about encrytption and decryption,, i have done the encryption part and its working just fine, but when i come to the decryption one , i am stuck

the question is asking to encrypt a 4 digit integer and replace each integer with (the sum of that digit plus 7) modulus 10
then swap first digit with the third ,, and the fourth digit with the second

then afterwards right a program that decrypts the integer

heres the program i wrote about the encryption , hope u could help me with the decryption one


Code:
// encryption.cpp
// how to encrypt a 4-digit integer

#include <iostream.h>


int main()
{

int data;
int digit;
int divider = 1000;
int encrypted = 0;
cout << "Enter a four-digit number to be encrypted: "<< endl;

cin>> data;



/* extract the fourth digit from the data by dividing it by 1000
e.g. 4567, we want to extract 4 so we divide 1000, the answer will be 4.567 but only 4 
will remain because we declared it as an integer.*/

for (int X = 0; X <= 3; X++) {

digit = data / divider;

data = data - (digit * divider);

digit = (digit + 7 ) % 10;

if (X == 0) 
	encrypted = encrypted + (digit * 10);

else if (X == 1)
	encrypted = encrypted + digit  ;


else if (X == 2)
	encrypted = encrypted + (digit*1000) ;

else if (X == 3)

	encrypted = encrypted + (digit * 100);

divider = divider / 10;


}
cout<< "the encrypted number is: " << encrypted;


return 0;
}
thankx eveyone

byoo