Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
eboda committed Jul 25, 2015
1 parent c021611 commit 82a6e4d
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,28 @@
# mersenne-twister-recover
Given at least 624 outputs of a Mersenne Twister PNRG we can restore its internal state.
Given at least 624 outputs of a Mersenne Twister we can restore its internal state.
The Mersenne Twister is used as PRNG in many programming languages such as PHP, Python, Ruby, etc.
Please refer to [Mersenne Twister](https://en.wikipedia.org/wiki/Mersenne_Twister) for detailed descriptions.



## Usage
Simply pass a list of observed outputs to the go() method:

```
r1 = random.Random(31337)
outputs = [r1.getrandbits(32) for _ in range(625)]
mtr = MT19937Recover()
r2 = mtr.go(outputs)
assert r1.getrandbits(32) == r2.getrandbits(32)
```

### Internal State
The internal state of a Mersenne Twister consists of 624 integers and an index.
Whenever a random number is requested, a tempering function is applied to the integer to which the index is currently pointing and the index is incremented.
When the index reaches 624, a new set of 624 integers is generated, which is called the *twist*.

### Recovering internal state
Recovering the internal state is done by applying the inverse of the tampering function to each observed output, which will yield the internal 624 integers.
However, if the observed 624 integers were not generated directly after a twist, another observed output is required to recover the correct index.

0 comments on commit 82a6e4d

Please sign in to comment.