1. ## Mod and calc

This is what has been annoying me just a bit and would appreciate any help. I have to write this program that encrypts and decrypts 4 character numbers.

For example..

Encrypt 3246 by adding 7 to each digit and modulus that total by 10.
(x+7) % 10

(3+7) % 10 = 0
(2+7) % 10 = 9
(4+7) % 10 = 1
(6+7) % 10 = 3

Now that was the easy part now I have to decrypt 0913 so I get the value 3246.

I tried to find the opposite calculation of modulus but to no avail. I would appreciate any help.

2. Lets look at it this way:
Your inital range of numbers is 0 - 9
By adding 7 to that number it shifts it to:
7 - 16
7 % 10 = 7
8 % 10 = 8
9 % 10 = 9
10 % 10 = 10
11 % 10 = 1
12% 10 = 2
13 % 10 = 3
14 % 10 = 4
15 % 10 = 5
16 % 10 = 6

So you know that if the number you are trying to decrypt is 0 then the orginal was 10 then you subtract 7 from it and get 3.

3. Alright thanks. Just one more question. When using functions and you have 4 variables to return is that even possible? Is there anyway to do it?

4. Yes, either:

1) pass all for four variables as parameters to the called function by reference (using either pointers or refernences)

2) return to the calling function an object of a user defined class/struct that contains all the desired values

3) send an object of a user defined class/struct containing all the desired data members to the called function, passing it by reference, of course

4) send an array that holds all the desired values to the called function; but then all the desired values need to be of the same type, which may or may not suit your needs.