i've made this simple encryption algorithm that takes a number and replace every digit with (digit+17)%10 while the digits are placed reversed in the new number
but i'm having trouble trying to make the decryption function..
i know that digit = (17+x)%10; but im not sure how to implement this ecuation into code... i cant figure the mathematic way since i never met modulo(%) in ecuations
#1 Property: (a + b) % c = (a % c + b) % c = (a % c + b) % c = (a % c + b % c) % c
#2 Corollary: (a + c) % c = (a % c + c % c) % c = (a % c + 0) % c = (a % c) % c = a % c
#3 Property: if 0 <= a < b then a % b = a
Therefore:
0 <= x < n
[by #3]
x % n = x
[by #2]
(x + n) % n = x
(x + k + n - k) % n = x
[by #1]
((x + k) % n + n - k) % n = x
Therefore: if
f(x) = (x + k) % n
and
g(x) = (x + n - k) % n
then g(f(x)) = x for all 0 <= x < n
Note: If b > c:
(a + b) % c =[by definition of integer division] (a + c * d + b % c) % c = (a + (c * d) % c + b % c) % c = (a + 0 + b % c) % c = (a + b % c) % c
Therefore (x + 17) % 10 = (x + 7) % 10