2009-02-05 21:08:46 +00:00
|
|
|
/*
|
2011-07-04 16:16:12 +00:00
|
|
|
* Copyright (C) 2007-2011
|
2010-01-04 00:25:52 +00:00
|
|
|
* pancake <youterm.com>
|
2009-02-05 21:08:46 +00:00
|
|
|
*
|
|
|
|
* radare is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* radare is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with radare; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
|
|
|
|
From Wikipedia, the free encyclopedia
|
|
|
|
|
|
|
|
In information theory, the Hamming distance between two strings of equal
|
|
|
|
length is the number of positions for which the corresponding symbols
|
|
|
|
are different. Put another way, it measures the minimum number of
|
|
|
|
substitutions required to change one into the other, or the number of
|
|
|
|
errors that transformed one string into the other.
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "r_types.h"
|
|
|
|
|
2010-04-08 10:29:47 +00:00
|
|
|
static int hamdist(int x, int y) {
|
2009-02-05 21:08:46 +00:00
|
|
|
int dist = 0, val = x^y;
|
2010-04-08 10:29:47 +00:00
|
|
|
while (val) {
|
2009-02-05 21:08:46 +00:00
|
|
|
++dist;
|
|
|
|
val &= val - 1;
|
|
|
|
}
|
|
|
|
return dist;
|
|
|
|
}
|
|
|
|
|
2010-04-08 10:29:47 +00:00
|
|
|
R_API ut8 r_hash_hamdist(const ut8 *buf, int len) {
|
2010-01-04 00:25:52 +00:00
|
|
|
int i, x, y;
|
|
|
|
x = y = i = 0;
|
2010-04-08 10:29:47 +00:00
|
|
|
for (i=0; i<len; i++) {
|
2009-02-05 21:08:46 +00:00
|
|
|
y = buf[i];
|
2010-04-08 10:29:47 +00:00
|
|
|
x = hamdist (x, y);
|
2009-02-05 21:08:46 +00:00
|
|
|
}
|
|
|
|
return x;
|
|
|
|
}
|