[Math] Find Divisor and Dividend from Remainder

divisibility

I am developing some software to "Mutate" inline constants in source code to make them hard to read (eg. Obfuscation) and need a way to determine two values that when divided by each other gets a predetermined remainder.

I have read up on the Remainder theorem but am finding it difficult to wrap my head around exactly what I need to implement/determine.

Basically I need a way to do the following:

Original:

x = 12

Mutated:

x = 1561312 % 13

Of course the dividend and the divisor will be much larger (I'm thinking of values like 1825141394). I considered brute forcing, but I thought I might ask around math exchange if you knew a formula or algorithm that would do what I wanted 🙂

Best Answer

Work backwards. Given your remainder $r$ ($12$ in the example), make a "random" choice of $q$ and $m$, with $m\gt r$, and calculate $x=qm +r$. Then use $x\,\%\, m$.