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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.