well actually he said the same thing but then couldnt understand how i came up with code in the first place |
Just because a function is invertible in a subset of its domain doesn't mean it's completely invertible. See for example x*x and sqrt(x). You can't prove that the function you wrote is the inverse of this for all possible inputs.
% isnt really what mathmeticians call modulos its the coding version (it has a different name i think modulous just cought on) |
The difference is only relevant for negative integers. For naturals, % is equivalent to the remainder function.
The remainder of the division a/b is an integer r such that a = b*q+r, where q is some integer and 0<=r<b. If cipher is a multiple of 27, then it's expressible as 27*k, where k is some integer. Then
(a+b)*cipher%27 == (a+b)*(27*k)%27 == (a*27*k+b*27*k)%27 ==
by properties of remainder:
== ((a*27*k)%27+(b*27*k)%27)%27 ==
and again:
== (((a%27)*(27%27)*(k%27))%27+((b%27)*(27%27)*(k%27))%27)%27 ==
by definition of remainder, for all integer values of c different than 0, c%c == 0. In particular, 27%27 == 0:
== (((a%27)*0*(k%27))%27+((b%27)*0*(k%27))%27)%27 ==
== (0%27+0%27)%27 == 0%27 == 0
Trust me, I've been doing proofs like this all year. The function is not fully invertible.