Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is this algorithm for generating random numbers called?

I have reverse engineered the follow algorithm for generating random numbers;

int __cdecl sub_40BB60()
{
  char v0; // si@1
  int v1; // edx@1
  int v2; // ecx@1
  unsigned int v3; // eax@1
  int v4; // edi@1
  int v5; // esi@1
  int result; // eax@1

  v0 = random_state;
  v1 = dword_685440[((_BYTE)random_state - 3) & 0xF];
  v2 = dword_685440[random_state] ^ v1 ^ ((v1 ^ 2 * dword_685440[random_state]) << 15);
  v3 = ((unsigned int)dword_685440[((_BYTE)random_state - 7) & 0xF] >> 11) ^ dword_685440[((_BYTE)random_state - 7) & 0xF];
  v4 = v3 ^ dword_685440[random_state] ^ v1 ^ ((v1 ^ 2 * dword_685440[random_state]) << 15);
  dword_685440[random_state] = v4;
  v5 = (v0 - 1) & 0xF;
  result = dword_685440[v5] ^ v2 ^ v4 ^ 32 * (v4 & 0xFED22169) ^ 4 * (dword_685440[v5] ^ ((v2 ^ (v3 << 10)) << 16));
  random_state = v5;
  dword_685440[v5] = result;
  return result;
}

dword_685440 is an int[16], and random_state is mutated as you can see.

I was thinking it may be a twister. Does anyone recognize this algorithm?

like image 267
kvanbere Avatar asked Oct 20 '22 17:10

kvanbere


1 Answers

Looks like it could be a linear feedback shift register algorithm. Those can be implemented at the word level by a combination of bit shifting and XOR operations, which is what this seems to be up to.

like image 148
pjs Avatar answered Oct 24 '22 00:10

pjs