samedi 25 mai 2019

Reversing LCG in java

I'm trying to get the original value that produces this random number.

Random rand = new Random(295);
int nextInt = 0;
for (int n = 0; n < 78801 + 1; n++) {
    nextInt = rand.nextInt(500000);
}
System.out.println(nextInt);//499429

The value (499429) was produced by seed (295) and it's the 78801th nextInt. I have done lots of research, according to the attached links, LCG is reversible. How can I reverse it in java such that using only the seed value and the output I will get back the nth value?

Making a customizable LCG that travels backward and forward

Reversible pseudo-random sequence generator

pseudo random distribution which guarantees all possible permutations of value sequence - C++

Reversible Linear Congruential Generator

Cracking a linear congruential generator

Cracking Random Number Generators - Part 1

Reverse engineering the seed of a linear congruential generator

Predicting the next Math.random() in Java

Inverse function of Java's Random function




Aucun commentaire:

Enregistrer un commentaire