1. ## Xor

Hi! I am actually a PHP programmer Not a Maths Guy .
I was making a strong Xor encryption function. While doing that I wondered on this three numbers (10, 20, 30).
Code:
10 Xor 20 Xor 30 Xor S results S
Code:
10 Xor S Xor 30 Xor 20 results S
e.g. Wherever I put the S it results to S if the numbers are 10, 20, 30 Why its happening ?? Please help .

2. Originally Posted by neel_basu
Hi! I am actually a PHP programmer Not a Maths Guy .
I was making a strong Xor encryption function. While doing that I wondered on this three numbers (10, 20, 30).
Code:
10 Xor 20 Xor 30 Xor S results S
Code:
10 Xor S Xor 30 Xor 20 results S
e.g. Wherever I put the S it results to S if the numbers are 10, 20, 30 Why its happening ?? Please help .
Look up the definition of xor, then look up the codes for 10, 20, 30, and S
you should pay particular attention to how it will interpret 10, 20 and 30
(convert to binary if necessary, it will be)

RonL

3. Binary Format
Code:
10 : 1010
20 : 10100
30 : 11110
I've tried it But not getting any Answer .

4. Originally Posted by neel_basu
Binary Format
Code:
10 : 1010
20 : 10100
30 : 11110
I've tried it But not getting any Answer .

Are you sure that 10: 1010 rather than 00001010?

xor(00010100,00011110)=00001010

so:

xor(xor(00010100,00011110),00001010)=00000000

(binary add without carry, also I have set them to a field width of 8 bits which realy does not make a lot of difference but may well be what the machine is doing)

RonL

5. Sorry But I didnt understand why its results S if the numbers are 10, 20, 30
can you plese explain more .

6. Well I've simplified my Problem
Code:
10 Xor 20 Xor 30 is 0
and
Code:
0 Xor S results S
And
10 Xor 20 = 30
10Xor 30 = 20
20 Xor 30 = 10
...................................
In a Cyclick order.
And I think If an Expression with Xor results 0 it means
Say a Xor b Xor c Xor d Xor e ........ = 0
then
b Xor c Xor d Xor e ........ = a
a Xor c Xor d Xor e ........ = b
....................................
e.g. Xor of all other element must be equal to the 1(or more Xored) rest element(s)
e.g. if its a Xor b Xor c Xor d = 0
a Xor c = b Xor d
a Xor d = b Xor d
and so on.

7. Originally Posted by neel_basu
Well I've simplified my Problem
Code:
10 Xor 20 Xor 30 is 0
and
Code:
0 Xor S results S
And
10 Xor 20 = 30
10Xor 30 = 20
20 Xor 30 = 10
...................................
In a Cyclick order.
And I think If an Expression with Xor results 0 it means
Say a Xor b Xor c Xor d Xor e ........ = 0
then
b Xor c Xor d Xor e ........ = a
a Xor c Xor d Xor e ........ = b
....................................
e.g. Xor of all other element must be equal to the 1(or more Xored) rest element(s)
e.g. if its a Xor b Xor c Xor d = 0
a Xor c = b Xor d
a Xor d = b Xor d
and so on.
Each bit of the multiple xor is 1 if there are an odd number of bits set in that
bit position and zero otherwise. There are an even number of bits set in each
position in 10, 20 and 30, so when xor-ed with any bit pattern in any order
the result has the same bit pattern as the extra bit pattern.

Alternate explanation is that xor is both associative and comultative so the
order of xor-s does not matter, so as 10 xor 20 xor 30 = 0 the result follows.

RonL

8. Ok thanks I've Understood.