-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBitPairsTable.cs
More file actions
55 lines (45 loc) · 1.46 KB
/
BitPairsTable.cs
File metadata and controls
55 lines (45 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System;
namespace tlsh.digests
{
internal class BitPairsTable
{
private const int BitPairsDiffTableSize = 256;
private static readonly int[][] BitPairsDiffTable = GenerateDefaultBitPairsDiffTable();
private static int[][] GenerateDefaultBitPairsDiffTable()
{
int[][] result = new int[BitPairsDiffTableSize][];
for (int i = 0; i < BitPairsDiffTableSize; i++)
{
for (int j = 0; j < BitPairsDiffTableSize; j++)
{
int x = i;
int y = j;
int diff = 0;
for (int z = 0; z < 4; z++)
{
int d = Math.Abs(x % 4 - y % 4);
if (d == 3)
{
diff += d * 2;
}
else
{
diff += d;
}
if (z < 3)
{
x /= 4;
y /= 4;
}
}
result[i][j] = diff;
}
}
return result;
}
public static int GetValue(int row, int column)
{
return BitPairsDiffTable[row][column];
}
}
}