Very Basic Encrypt/Decrypt

Started by
2 comments, last by GameDev.net 19 years, 6 months ago
I am doing an exercise from a C++ books, and it says i have to encrypt a number, by getting each digit and replaces it with (the sum of the digit + 7) % 10. Now that works perfect. But I have a hell of a time decrypting. Mainly what in the the world is the opposite of % 10 ? Please help...thanks.
Advertisement
14%10 = 4
4%10 = 4

its inposible to decrypt
Quote:Original post by mike25025
14%10 = 4
4%10 = 4

its inposible to decrypt
No it isn't, because in this case you have a 1-1 mapping of input to output.
It sounds like homework though, so I won't solve it for you.
"Walk not the trodden path, for it has borne it's burden." -John, Flying Monk
If N is your encrypted number, then you can decrypt it with (N + 3) % 10. This is because for any digit n, ((n + 7) + 3) % 10 = n, because n is between 0 and 9.

This topic is closed to new replies.

Advertisement