In my discrete maths homework, I'm being asked to find the inverse of a cipher function:
$f(p) = (3p + 5) \bmod{26}$
$f(p)$ accepts natural integers of the range ${0,1,...,25}$ (where A = $0$ and Z = $25$) and outputs in the same range.
Messing around for a lot of time, I ended up finding this function:
$f^{-1}(p) = \Big(\frac{p + 26(p \bmod{3})}{3} + 7\Big) \bmod{26}$
But it was obtained almost exclusively with the help of trial and error and C program I made to help me investigate, and that's not quite suitable to write on my copy.
First, is my function the best function that solves this problem? And second, how should I have found this the 'right' way?