Search code examples
encryptionxor

Find the value used for XOR


I have the initial address and the output .. I need to find out what was used for XOR

129.94.5.93:46 XOR ????? == 10.165.7.201:14512

Solution

  • XOR has an interesting property that if you apply it to one of its operands and the result, you get the other operand back. In other words, if

    r = a ^ b
    

    then

    b = r ^ a
    

    where a and b are operands, and r is the result.

    Hence, the data with which the original has been XOR-ed is

    139.251.2.148:14494
    

    Here is a short program in C# to produce this result from your data:

    var a = new[] {129,94,5,93,46};
    var b = new[] {10,165,7,201,14512};
    var c = new int[a.Length];
    for (int i = 0 ; i != a.Length ; i++) {
        c[i] = a[i] ^ b[i];
        Console.WriteLine("a={0} b={1} c={2} back={3}", a[i], b[i], c[i], c[i] ^ a[i]);
    }
    

    Here is a link to ideone showing this program in action.