-1

I have two bit masks:

public static UInt64 Mask0 = 0xFFFFFFFF00000000UL;
public static UInt64 Mask1 = 0x00000000FFFFFFFFUL;

I have a ulong value:

UInt64 value = 0x1089000000054321;

Then based on a condition, I xor the value with one of the two bit masks.

if (condition == true)
    value ^= Mask0;
else
    value ^= Mask1;

Now the problem is that the value should be dynamic (unpredictable), and will change dynamically when the code is run. I actually won't know the original value (original value before being xored with the Mask). I just need to precisely check/detect which Mask (Mask0 or Mask1) was xored with the value. Any help will be appreciated.

Jain
  • 1
  • 2
  • If you XOR a value and then take the results you will always get the original value So to find out which mask was used take each mask and xor with value. Then see which one give original value. So ((value ^ mask0) ^ mask0) == value. – jdweng Sep 07 '19 at 07:46

1 Answers1

1

There is no way of determining this. Bit wise XOR is an operation whose result will depend on two input values, just like addition or multiplication.

Your question is similar to this:

If I have a number (N) which was derived by taking an unknown number (X) to which I either added 1 or 2 based on a condition (C) (which I do not know), can I determine whether I added 1 or 2 to X by looking at N?

Jens Meinecke
  • 2,904
  • 17
  • 20