Your function:
uint Function(uint value)
{
return value * 0x123456D;
}
multiplies in uint
(which works just like the integers modulo 2**64
in so-called unchecked
context) by an odd number. Such an odd number has a unique inverse, modulo 2**64
. In this case it is 0xE2D68C65u
, because as you may check (C# syntax):
unchecked(0x123456Du * 0xE2D68C65u) == 1u
This multiplication is associative and commutative. So your "reverse" method is:
uint UndoFunction(uint value)
{
return value * 0xE2D68C65u;
}
(unckecked
context assumed).
For any input x
, both UndoFunction(Function(x))
and Function(UndoFunction(x))
give you back the original x
.
PS! To find the modular inverse 0xE2D68C65u
, I used something other than .NET. Actually GP/PARI like Charles in his answer. In GP, you can do 1/Mod(19088749, 2^32)
or Mod(19088749, 2^32)^-1
. It uses decimal notation by default.