Jump to content

Need help with part of PHP code - encryption!


Malyghos

Recommended Posts

"^" is a bitwise operator called Xor (exclusive or), that basically checks the bits between the given arguments, and sets all the bits to 1 where they're only set to 1 in one of the arguments.

 

As a quick example:

 

1001 ^ 1000 = 0001

 

.. Because the first bit is set in both arguments, but the last bit is only set in the first.

It is a bitwise operator http://fi.php.net/manual/en/language.operators.bitwise.php

 

And it compares binary values of two numbers. It searches for bits that are set in only one of the numbers. For example binary for 5 = 0101 and binary for 8 = 1000

 

so in comparsion of 5 ^ 8 = 13

 

because

       BITS
5:    0 1 0 1
8:    1 0 0 0 
R:    1 1 0 1  and decimal value for 1101 = 13

6:    0 1 1 0
7:    0 1 1 1
R:    0 0 0 1 and decimal value for 0001 = 1

so 5 ^ 8 = 13
and 6 ^ 7 = 1

same result with 8 ^ 5  or 7 ^ 6 because bits dont change. They are just compared. And depends on which operator you use what it will return.

 

You dont have to change your numbers because bitwise operators compare the numbers in binary-level.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.