uint32_t myrand(void)
{
static uint32_t vec[] = {1, 1812433254, 3713160357, 3109174145};
static int i = 4;
__m128i x, y, z;
if (i == 4) {
x = _mm_load_si128((__m128i *)vec);
y = _mm_xor_si128(x, _mm_slli_si128(x, 1));
z = _mm_xor_si128(y, _mm_srli_si128(_mm_srli_epi64(y, 5), 8));
_mm_store_si128((__m128i *)vec, _mm_xor_si128(z, _mm_slli_si128(_mm_slli_epi64(z, 11), 8)));
i = 0;
}
return vec[i++];
}
void set_random_key(MULTI2 *m2)
{
uint8_t key[8];
uint32_t n;
n = myrand();
key[0] = (n >> 24) & 0xFF;
key[1] = (n >> 16) & 0xFF;
key[2] = (n >> 8) & 0xFF;
key[3] = (n >> 0) & 0xFF;
n = myrand();
key[4] = (n >> 24) & 0xFF;
key[5] = (n >> 16) & 0xFF;
key[6] = (n >> 8) & 0xFF;
key[7] = (n >> 0) & 0xFF;
m2->set_scramble_key(m2, key);
}
dWludDMyX3QgbXlyYW5kKHZvaWQpCnsKICAgIHN0YXRpYyB1aW50MzJfdCB2ZWNbXSA9IHsxLCAxODEyNDMzMjU0LCAzNzEzMTYwMzU3LCAzMTA5MTc0MTQ1fTsKICAgIHN0YXRpYyBpbnQgaSA9IDQ7CiAgICBfX20xMjhpIHgsIHksIHo7CiAgICBpZiAoaSA9PSA0KSB7CiAgICAgICAgeCA9IF9tbV9sb2FkX3NpMTI4KChfX20xMjhpICopdmVjKTsKICAgICAgICB5ID0gX21tX3hvcl9zaTEyOCh4LCBfbW1fc2xsaV9zaTEyOCh4LCAxKSk7CiAgICAgICAgeiA9IF9tbV94b3Jfc2kxMjgoeSwgX21tX3NybGlfc2kxMjgoX21tX3NybGlfZXBpNjQoeSwgNSksIDgpKTsKICAgICAgICBfbW1fc3RvcmVfc2kxMjgoKF9fbTEyOGkgKil2ZWMsIF9tbV94b3Jfc2kxMjgoeiwgX21tX3NsbGlfc2kxMjgoX21tX3NsbGlfZXBpNjQoeiwgMTEpLCA4KSkpOwogICAgICAgIGkg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