
decryption>> need help
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 4digit integer
#include <iostream.h>
int main()
{
int data;
int digit;
int divider = 1000;
int encrypted = 0;
cout << "Enter a fourdigit 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

Maybe this will help....
I assume the problem is reversing this part: (the sum of that digit plus 7) modulus 10.
I made a chart of that operation:
0 > 7
1 > 8
2 > 9
3 > 0
4 > 1
5 > 2
6 > 3
7 > 4
8 > 5
9 > 6
To reverse that, it looks like you add 3, and then "throwaway" any digits in the 10's place.

hey doug
can u explain alittel bit more , cause i didnt get the i dea how to throw away and digits in the 10's place???????????
thx again
byoo

Know what operator % is??

any one can help???????
i need to finish my assgment

> but when i come to the decryption one , i am stuck
Just read the instructions backwards.
> then swap first digit with the third ,, and the fourth digit with the second
What's the reverse of this?
> digit = (digit + 7 ) % 10;
Here's a hint
digit = digit + 7; if ( digit >= 10 ) digit = digit  10;
Is a lot easier to do when you need to start thinking about the decrypt process.

hey
thx for the hint
and i think that i have fount the soluation
but i need someone to check it out
Code:
// deycryption.cpp
// how to decrypte a 4digit integer
#include <iostream.h>
int main()
{
int data;
int digit;
int divider = 1000;
int decrypted = 0;
cout << "Enter the four digit encrypted number to be decrypted: "<< endl;
cin>> data;
for (int X = 0; X <= 3; X++) {
digit = data / divider;
data = data  (digit * divider);
digit = ((digit + 10 ) % 10) + 3;
if (X == 0)
decrypted = decrypted + (digit * 10);
else if (X == 1)
decrypted = decrypted + digit ;
else if (X == 2)
decrypted = decrypted + (digit*1000) ;
else if (X == 3)
decrypted = decrypted + (digit * 100);
divider = divider / 10;
}
cout<< "the encrypted number is: " << decrypted;
return 0;
}
byooo

anyone ????
help!!!!!!!!!

Why not just test it yourself? Either by hand, working through it step by step, or easier, compile and run it, put in numbers, see if you get the same back out.

Absolutely, takes all of 10 seconds to compile it and try some stuff.
If you can't be bothered to test your own code, give up now.