Let f(p) = a*p + b (mod m)
Where a and m are relatively prime.
What is the inverse function of f?
This is confusing because generally we talk about inverse of a number not a function.
So what I understand is we have to find a function g() such that
f(p) *g() = 1 (mod m)
How to go about it?
The same as any inverse fuction.
The functions so that $f(f^{-1}(p)) = p$.
Set $f^{-1}(p) = y$ (just so we can avoid typing
And $f(y) \equiv a*y + b \equiv p \pmod m$ and solve for $y$.
$ay + b \equiv p \pmod m$
$ay \equiv p-b \pmod m$
Now $a$ and $m$ are relatively prime so $a^{-1}$ exists.
$y \equiv a^{-1}(p -b)\pmod m$.
So $f^{-1}(p) = a^{-1}(p-b)\pmod m$.
That's all there is to it.
For any $p \in \mathbb Z_m$ then if $K = a*y+b$ then $f^{-1}(K) = a^{-1}(K-b)= a^{-1}([ap+b] - b) \equiv a^{-1}(ap) \equiv p\pmod m$.