int main( int argc, char *argv[] ) { mtrng_t mt; srand(42); //Wait for a random time printf("Sleeping...\n"); sleep( (rand()%1000) + 40); int seed = time(NULL); SeedMT( &mt, seed ); printf("Seeded...\n"); printf("Sleeping...\n"); sleep( (rand()%1000) + 40); printf("Woke up!...\n"); uint32_t first = ExtractNumber( &mt ); int i; int currTime = time(NULL); mtrng_t temp; for( i = 0; i < 100000; i++ ){ SeedMT( &temp, currTime ); uint32_t num = ExtractNumber( &temp ) ; if( num == first ) { printf("FOUND:%d\n", currTime ); printf("Used Seed:%d\n", seed ); break; } currTime--; } return 0; }
bool RakNetRandomSync::DeserializeConstruction(RakNet::BitStream *constructionBitstream) { uint32_t _seed; uint32_t _skipValues; constructionBitstream->Read(_seed); bool success = constructionBitstream->Read(_skipValues); if (success) SeedMT(_seed, _skipValues); return success; }
void EncodePRNG( uint16_t seed, byte_t *data, int size ) { mtrng_t mt; SeedMT( &mt, seed ); int i; for( i = 0; i < size; i++ ) { byte_t num = ExtractNumber( &mt )%256; data[i] = data[i] ^ num; } }
int main( int argc, char *argv[] ) { srand(time(NULL)); int size = ( rand()%300 ) + 100; uint16_t s16 = rand()%0x10000; printf("Seed:%d\n",s16); byte_t *buffer = malloc(size); int i; for( i = 0; i < size-14; i++ ) { buffer[i] = rand(); } for( ; i < size; i++ ) { buffer[i] = 'A'; } buffer[i] = '\0'; for( i = 0; i < size; i++ ) printf("%02x",buffer[i]); printf("\n"); EncodePRNG( s16, buffer, size ); for( i = 0; i < size; i++ ) printf("%02x",buffer[i]); printf("\n"); uint16_t nseed; mtrng_t mt2; for( i = 0; i < 0x10000; i++ ) { SeedMT( &mt2, i); int j; int ding = 0; for( j = 0; j < size; j++ ) { if( j < (size-14) ) { ExtractNumber( &mt2 ); } else { if( ((ExtractNumber( &mt2 )%256) ^ buffer[j] ) == 'A' ) { ding++; } } } if( ding == 14 ) { printf("dingnumber:%d %d\n",ding,i); nseed = i; } } EncodePRNG( nseed, buffer, size ); for( i = 0; i < size; i++ ) printf("%02x",buffer[i]); printf("\n"); return 0; }
void RakNetRandomSync::SeedMT( uint32_t _seed, uint32_t skipValues ) { SeedMT(_seed); Skip(skipValues); }