Results 1 to 8 of 8

Math Help - Xor

  1. #1
    Newbie
    Joined
    Aug 2007
    Posts
    11

    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 .
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by neel_basu View Post
    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
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Newbie
    Joined
    Aug 2007
    Posts
    11
    Binary Format
    Code:
    10 : 1010
    20 : 10100
    30 : 11110
    I've tried it But not getting any Answer .
    about this magic .
    Follow Math Help Forum on Facebook and Google+

  4. #4
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by neel_basu View Post
    Binary Format
    Code:
    10 : 1010
    20 : 10100
    30 : 11110
    I've tried it But not getting any Answer .
    about this magic .

    Are you sure that 10: 1010 rather than 00001010?

    and what about S?

    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
    Follow Math Help Forum on Facebook and Google+

  5. #5
    Newbie
    Joined
    Aug 2007
    Posts
    11
    Sorry But I didnt understand why its results S if the numbers are 10, 20, 30
    can you plese explain more .
    Follow Math Help Forum on Facebook and Google+

  6. #6
    Newbie
    Joined
    Aug 2007
    Posts
    11
    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.
    Follow Math Help Forum on Facebook and Google+

  7. #7
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by neel_basu View Post
    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
    Last edited by CaptainBlack; August 1st 2007 at 11:44 AM.
    Follow Math Help Forum on Facebook and Google+

  8. #8
    Newbie
    Joined
    Aug 2007
    Posts
    11
    Ok thanks I've Understood.
    Follow Math Help Forum on Facebook and Google+

Search Tags


/mathhelpforum @mathhelpforum