This problem is more mathematic than programming question. I have function which is decoding license key and checking its correctness.
See code:
ushort local6 = rand1; // generated random = 0x2ff2
ushort local1 = rand2; // = 0x780e
ushort local8 = rand3; // = 0x1e3c
ushort local4 = rand4; // = 0xf521
ushort temp1 = 0; // always zero
ushort temp2 = 0; // always zero
// THIS loop
for (int i = 0; i < 8; i++)
{
local6 += stack2[0 + 6 * i];
local1 += stack2[1 + 6 * i];
local8 += stack2[2 + 6 * i];
local4 += stack2[3 + 6 * i];
temp1 = (ushort)(local6 ^ local8);
temp1 += stack2[4 + 6 * i];
temp2 = (ushort)((local1 ^ local4) + temp1);
temp2 += stack2[5 + 6 * i];
temp1 += temp2;
local6 = (ushort)(local6 ^ temp2);
local4 ^= temp1;
temp1 ^= local1;
local1 = (ushort)(local8 ^ temp2);
local8 = temp1;
}
// Results after loop:
// local6 = 0x518a
// local1 = 0x33e5
// local8 = 0x8bca
// local4 = 0x57de
// validate date, checksums etc.
if (_validate(local6, local8, local1, local4))
return "Key " + rand1 + "-" + "rand2" + "-" + "rand3" + "-" + "rand4" + " is valid!";
else
return "Key invalid!";
To make it simplier lets assume:
ushort[] stack2 = new ushort[52];
for (int i = 0; i < stack2.Length; i++)
{
stack2[i] = (ushort)i;
}
Question is; Is this loop reversable? I mean is it possible to retrieve values
rand1, rand2, rand3, rand4
from values taken after loop:
local6, local1, local8, local4
with knowledge of the code of loop function? I am almost sure this is not possible but want to know what You think about this.
Code I'm sharing is mine invention and I truly believe this kind of loop can be good protection versus reverse engineers (serial crackers) unless they bruteforcing.