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