Candace said:
This is for a class that I am taking. I'm just learning to program. The
instructions said "Your program should read a four-digit Integer entered by
the user and encrypt it as follows: Replace each digit by (the sum of that
digit and 7) modulo 10. Then write a program that inputs an encryption
four-digit Integer and decrypts it to form the original number." Do you think
I could be miss-understanding the instructions? Or are you reading it as the
same meaning that I am?
Try looking at the problem a little differently, and I think you'll get
it.
What Mod 10 actually does to a whole number is remove everything except
the rightmost digit, right?
Suppose your original digit is 5. You have to add 7. Try incrementing
5 by 1, seven times, in your head - but remember, you can never reach
double digits. When you pass nine, start back at zero. 5 becomes 6,
7, 8, 9, 0, 1, 2. So 2 is your encrypted version of 5.
To decrypt: 2 becomes 1, 0, 9, 8, 7, 6, 5.
Now see if you can find a mathematical way to decrypt a single digit in
*one* line of code. If you can't, I'll tell you - but you learn more
this way; gotta exercise the brain to get really good at this stuff.