MCPcopy Create free account
hub / github.com/CDSecLab/MJXT / Xor8

Method Xor8

src/main/java/utils/Xor8.java:33–133  ·  view source on GitHub ↗
(long[] keys, byte[][] ct)

Source from the content-addressed store, hash-verified

31
32
33 public Xor8(long[] keys, byte[][] ct) {
34 this.size = keys.length;
35 arrayLength = getArrayLength(size);
36 bitCount = arrayLength * BITS_PER_FINGERPRINT;
37 blockLength = arrayLength / HASHES;
38 int m = arrayLength;
39 ciphertext = new byte[m][];
40 long[] reverseOrder = new long[arrayLength];
41 byte[] reverseH = new byte[arrayLength];
42 int reverseOrderPos;
43 long seed;
44 do {
45 seed = Hash.randomSeed();
46 byte[] t2count = new byte[m];
47 long[] t2 = new long[m];
48 for (int i = 0; i < size; i++) {
49 long k = i;
50 for (int hi = 0; hi < HASHES; hi++) {
51 int h = getHash(keys[i], seed, hi);
52 t2[h] ^= k;
53 if (t2count[h] > 120) {
54 // probably something wrong with the hash function
55 // let us not crash the system:
56 throw new IllegalArgumentException();
57 }
58 t2count[h]++;
59 }
60 }
61 reverseOrderPos = 0;
62 int[][] alone = new int[HASHES][blockLength];
63 int[] alonePos = new int[HASHES];
64 for (int nextAlone = 0; nextAlone < HASHES; nextAlone++) {
65 for (int i = 0; i < blockLength; i++) {
66 if (t2count[nextAlone * blockLength + i] == 1) {
67 alone[nextAlone][alonePos[nextAlone]++] = nextAlone * blockLength + i;
68 }
69 }
70 }
71 int found = -1;
72 while (true) {
73 int i = -1;
74 for (int hi = 0; hi < HASHES; hi++) {
75 if (alonePos[hi] > 0) {
76 i = alone[hi][--alonePos[hi]];
77 found = hi;
78 break;
79 }
80 }
81 if (i == -1) {
82 // no entry found
83 break;
84 }
85 if (t2count[i] <= 0) {
86 continue;
87 }
88 long k = t2[i];
89
90 if (t2count[i] != 1) {

Callers

nothing calls this directly

Calls 6

getArrayLengthMethod · 0.95
randomSeedMethod · 0.95
getHashMethod · 0.95
Get_SHA_256Method · 0.95
longToBytesMethod · 0.80
XorMethod · 0.80

Tested by

no test coverage detected