Mod and calc

• 03-08-2005
StarOrbs
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.
• 03-08-2005
Thantos
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.
• 03-08-2005
StarOrbs
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?
• 03-08-2005