Malyghos Posted December 23, 2010 Share Posted December 23, 2010 Hello, I have one line that I can't understand of PHP code used to encrypt strings: $temp = ord(substr($str,$i,1)) ^ 203; I understand everything but this " ^203 " Can you explain me what it does? Quote Link to comment https://forums.phpfreaks.com/topic/222478-need-help-with-part-of-php-code-encryption/ Share on other sites More sharing options...
Adam Posted December 23, 2010 Share Posted December 23, 2010 "^" 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. Quote Link to comment https://forums.phpfreaks.com/topic/222478-need-help-with-part-of-php-code-encryption/#findComment-1150687 Share on other sites More sharing options...
Malyghos Posted December 23, 2010 Author Share Posted December 23, 2010 Thank you very much! I am doing this manually. So, should I change ORD(whatever) and 203 to binary and then XOR them? Quote Link to comment https://forums.phpfreaks.com/topic/222478-need-help-with-part-of-php-code-encryption/#findComment-1150688 Share on other sites More sharing options...
Adam Posted December 23, 2010 Share Posted December 23, 2010 I'm not sure. What are you trying to do? ord(whatever) and 203 would be be compared at bit-level by the Xor operator. Quote Link to comment https://forums.phpfreaks.com/topic/222478-need-help-with-part-of-php-code-encryption/#findComment-1150691 Share on other sites More sharing options...
johnny86 Posted December 23, 2010 Share Posted December 23, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/222478-need-help-with-part-of-php-code-encryption/#findComment-1150694 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.