tags:

views:

309

answers:

2

Hello,

here are 5 binary strings base64_encode()'ed

wAD4Af8B/gHuA/4BzgP1A/8P/h//f/xv+z30D9IDSAE=

AAAgCPgf/B/4H/w1+B74Gfg/+B/8P/4f/D/8HwABAAA=

AAAAAMB/wP/A/8B/4HvAf+B/+n/3P/Y//z/4n4CDgAE=

AAAAXcB/wH/Af8B/wHfAP+B/6H/xf+7//r/4f0CngFY=

AAiwifAP+B/4D/gf8B74D/gd8V/4H/gP8B/8vwABAAA=

AAAAAAAA/QD/Af4B/iP+A/wD/A/+//7/+B+AAwAAAAA=

How can I XOR (^) each of them in pairs and count the 1bits in the result. Sounds like it should be simple but I have no idea how to work with binary in PHP.

Thanks!

A: 

hello,

you can find more about logical operators here: http://php.net/manual/en/language.operators.logical.php

dusoft
Yes I know about those as I mentioned in the question.
Kiril Angov
A: 

The pack and unpack functions are the ones you want to look at. They allow conversion to and from binary strings.

Of course you will also have to use the base 64 decoding function and the bitwise functions

Yacoby
The problem is what options to unpack to use in order to be able to get the binary in a format where I can count the 1's and 0's.$result = $binary1 ^ $binary2;$string = unpack([...], $result);$counts = count_chars($string);// 1's = $counts[49] and 0's = $counts[48]The problem again is how to get the $string variable correct. Thanks.
Kiril Angov