XOR binary values greater than 64bit I have a binary blob holding the results of a SHA256 hash that I XOR with a script generated SHA256 hash. For testing I am using the values usertokens and methodtoken for the test hashes.

hash1: string(64) "439c366749b149e0238c249682e015603efa46660a3c647d08bce69a184a7ab2" 
hash2: string(64) "c0196f85f4d764213504089251c6bc0726610bcf5e62fc2c1cbd7ee3aebe2d43" &gt;
script combo: string(64) "838559e2bd662dc116882c04d326a967189b4da9545e985114019879b6f457f1" 
mysql combo:  string(3) "439" 


PHP:

$combo = bin2hex($hash1 xor $hash2);


MYSQL:

SELECT `hash1` ^ `hash2` as combo


As far as I can tell, the issue is that bit-wise XOR is limited to 64bit values, but I can't find a straightforward way to bi-wise XOR larger values.
Perhaps you could the following:


split each value into little two character strings
convert each 2-character string into a decimal numebr
XOR each decimal number side by side
CONCAT all results
Lower Case the Result


Sounds simple, eh??

Wanna see the code in MySQL ??

Here we go ...

SET @h1 = '439c366749b149e0238c249682e015603efa46660a3c647d08bce69a184a7ab2';
SET @h2 = 'c0196f85f4d764213504089251c6bc0726610bcf5e62fc2c1cbd7ee3aebe2d43';
SELECT LCASE(GROUP_CONCAT(HEX(v1^v2) SEPARATOR '')) HashResult FROM
(SELECT x,CONV(SUBSTR(@h1,x,2),16,10) v1,CONV(SUBSTR(@h2,x,2),16,10) v2
FROM (SELECT z+z-1 x FROM
(SELECT      1 z UNION SELECT  2 UNION SELECT  3 UNION SELECT  4
 UNION SELECT  5 UNION SELECT  6 UNION SELECT  7 UNION SELECT  8
 UNION SELECT  9 UNION SELECT 10 UNION SELECT 11 UNION SELECT 12
 UNION SELECT 13 UNION SELECT 14 UNION SELECT 15 UNION SELECT 16
 UNION SELECT 17 UNION SELECT 18 UNION SELECT 19 UNION SELECT 20
 UNION SELECT 21 UNION SELECT 22 UNION SELECT 23 UNION SELECT 24
 UNION SELECT 25 UNION SELECT 26 UNION SELECT 27 UNION SELECT 28
 UNION SELECT 29 UNION SELECT 30 UNION SELECT 31 UNION SELECT 32
) AAA) AA) A;


Wanna see it executed ??? Here we go ...

mysql&gt; SET @h1 = '439c366749b149e0238c249682e015603efa46660a3c647d08bce69a184a7ab2';
Query OK, 0 rows affected (0.00 sec)

mysql&gt; SET @h2 = 'c0196f85f4d764213504089251c6bc0726610bcf5e62fc2c1cbd7ee3aebe2d43';
Query OK, 0 rows affected (0.00 sec)

mysql&gt; SELECT LCASE(GROUP_CONCAT(HEX(v1^v2) SEPARATOR '')) HashResult FROM
    -&gt; (SELECT x,CONV(SUBSTR(@h1,x,2),16,10) v1,CONV(SUBSTR(@h2,x,2),16,10) v2
    -&gt; FROM (SELECT z+z-1 x FROM
    -&gt; (SELECT      1 z UNION SELECT  2 UNION SELECT  3 UNION SELECT  4
    -&gt;  UNION SELECT  5 UNION SELECT  6 UNION SELECT  7 UNION SELECT  8
    -&gt;  UNION SELECT  9 UNION SELECT 10 UNION SELECT 11 UNION SELECT 12
    -&gt;  UNION SELECT 13 UNION SELECT 14 UNION SELECT 15 UNION SELECT 16
    -&gt;  UNION SELECT 17 UNION SELECT 18 UNION SELECT 19 UNION SELECT 20
    -&gt;  UNION SELECT 21 UNION SELECT 22 UNION SELECT 23 UNION SELECT 24
    -&gt;  UNION SELECT 25 UNION SELECT 26 UNION SELECT 27 UNION SELECT 28
    -&gt;  UNION SELECT 29 UNION SELECT 30 UNION SELECT 31 UNION SELECT 32
    -&gt; ) AAA) AA) A;
+----------------------------------------------------------------+
| HashResult                                                     |
+----------------------------------------------------------------+
| 838559e2bd662dc116882c4d326a967189b4da9545e98511419879b6f457f1 |
+----------------------------------------------------------------+
1 row in set (0.00 sec)

mysql&gt;


Give it a Try !!!

CAVEAT : Sorry, it's late and I was not in the mood to do a Stored Procedure !!!

If you are interested why this works, this query let's look at the details:

SELECT *,LCASE(HEX(v1^v2)) v3 FROM
(SELECT x,CONV(SUBSTR(@h1,x,2),16,10) v1,CONV(SUBSTR(@h2,x,2),16,10) v2
FROM (SELECT z+z-1 x FROM
(SELECT      1 z UNION SELECT  2 UNION SELECT  3 UNION SELECT  4
 UNION SELECT  5 UNION SELECT  6 UNION SELECT  7 UNION SELECT  8
 UNION SELECT  9 UNION SELECT 10 UNION SELECT 11 UNION SELECT 12
 UNION SELECT 13 UNION SELECT 14 UNION SELECT 15 UNION SELECT 16
 UNION SELECT 17 UNION SELECT 18 UNION SELECT 19 UNION SELECT 20
 UNION SELECT 21 UNION SELECT 22 UNION SELECT 23 UNION SELECT 24
 UNION SELECT 25 UNION SELECT 26 UNION SELECT 27 UNION SELECT 28
 UNION SELECT 29 UNION SELECT 30 UNION SELECT 31 UNION SELECT 32
) AAA) AA) A;


Here are the details:

mysql&gt; SELECT *,LCASE(HEX(v1^v2)) v3 FROM
    -&gt; (SELECT x,CONV(SUBSTR(@h1,x,2),16,10) v1,CONV(SUBSTR(@h2,x,2),16,10) v2
    -&gt; FROM (SELECT z+z-1 x FROM
    -&gt; (SELECT      1 z UNION SELECT  2 UNION SELECT  3 UNION SELECT  4
    -&gt;  UNION SELECT  5 UNION SELECT  6 UNION SELECT  7 UNION SELECT  8
    -&gt;  UNION SELECT  9 UNION SELECT 10 UNION SELECT 11 UNION SELECT 12
    -&gt;  UNION SELECT 13 UNION SELECT 14 UNION SELECT 15 UNION SELECT 16
    -&gt;  UNION SELECT 17 UNION SELECT 18 UNION SELECT 19 UNION SELECT 20
    -&gt;  UNION SELECT 21 UNION SELECT 22 UNION SELECT 23 UNION SELECT 24
    -&gt;  UNION SELECT 25 UNION SELECT 26 UNION SELECT 27 UNION SELECT 28
    -&gt;  UNION SELECT 29 UNION SELECT 30 UNION SELECT 31 UNION SELECT 32
    -&gt; ) AAA) AA) A;
+----+------+------+------+
| x  | v1   | v2   | v3   |
+----+------+------+------+
|  1 | 67   | 192  | 83   |
|  3 | 156  | 25   | 85   |
|  5 | 54   | 111  | 59   |
|  7 | 103  | 133  | e2   |
|  9 | 73   | 244  | bd   |
| 11 | 177  | 215  | 66   |
| 13 | 73   | 100  | 2d   |
| 15 | 224  | 33   | c1   |
| 17 | 35   | 53   | 16   |
| 19 | 140  | 4    | 88   |
| 21 | 36   | 8    | 2c   |
| 23 | 150  | 146  | 4    |
| 25 | 130  | 81   | d3   |
| 27 | 224  | 198  | 26   |
| 29 | 21   | 188  | a9   |
| 31 | 96   | 7    | 67   |
| 33 | 62   | 38   | 18   |
| 35 | 250  | 97   | 9b   |
| 37 | 70   | 11   | 4d   |
| 39 | 102  | 207  | a9   |
| 41 | 10   | 94   | 54   |
| 43 | 60   | 98   | 5e   |
| 45 | 100  | 252  | 98   |
| 47 | 125  | 44   | 51   |
| 49 | 8    | 28   | 14   |
| 51 | 188  | 189  | 1    |
| 53 | 230  | 126  | 98   |
| 55 | 154  | 227  | 79   |
| 57 | 24   | 174  | b6   |
| 59 | 74   | 190  | f4   |
| 61 | 122  | 45   | 57   |
| 63 | 178  | 67   | f1   |
+----+------+------+------+
32 rows in set (0.00 sec)

mysql&gt;