• This repository has been archived on 12/Apr/2022
  • Stars
    star
    163
  • Rank 231,101 (Top 5 %)
  • Language
    Python
  • Created over 8 years ago
  • Updated almost 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Predict MT19937 PRNG, from preceding 624 generated numbers. There is a specialization for the "random" of Python standard library.

Mersenne Twister Predictor

Travis PyPI PyPI PyPI PyPI Documentation Status

Predict MT19937 PRNG, from preceding 624 generated numbers. There is a specialization for the "random" of Python standard library.

usage

install

$ pip install mersenne-twister-predictor

as a library

This library has the special feature for CPython's standard random. Try below one:

import random
from mt19937predictor import MT19937Predictor

predictor = MT19937Predictor()
for _ in range(624):
    x = random.getrandbits(32)
    predictor.setrandbits(x, 32)

assert random.getrandbits(32) == predictor.getrandbits(32)

This is useful for some CTF tasks, e.g. TokyoWesterns CTF 4th 2018: mixed cipher, Tokyo Westerns CTF 3rd: 2017, etc. For more details, read the document.

as a command

Give the 624 32-bit integers, as unsigned decimal integers, line by line.

$ wc data.txt
 624  624 6696 data.txt

$ head -n 4 data.txt
734947730
363401994
806921074
790218357

$ cat data.txt | mt19937predict > predicted.txt

example (same as tests/cplusplus.py)

This is an example of a pseudorandom number generator using the Mersenne Twister.

// generator.cpp
#include <iostream>
#include <random>
using namespace std;
int main() {
    random_device seed_gen;
    mt19937 mt(seed_gen());
    for (int i = 0; i < 1000; ++i) {
        cout << mt() << endl;
    }
    return 0;
}

Compile it and let it generate 1000 numbers.

$ g++ -std=c++11 generator.cpp

$ ./a.out > data.txt

$ head data.txt
734947730
363401994
806921074
790218357
1766244801
680628322
1972477509
4015123394
2848130362
3481789813

Take the 624 consecutive numbers. We will predict the rest, 376 numbers.

$ head -n 624 data.txt > known.txt

$ tail -n 376 data.txt > correct.txt

$ wc known.txt
 624  624 6696 known.txt

Predict.

$ cat known.txt | mt19937predict | head -n 376 > predicted.txt

Compare the predict numbers and the original ones. If diff outputs nothing, it means the prediction was succeeded.

$ diff predicted.txt correct.txt

reference

thanks to

More Repositories

1

Jikka

an automated solver for problems of competitive programming
Haskell
134
star
2

competitive-programming-library

kimiyuki's library for competitive programming with C++
C++
65
star
3

libproofofwork

Simple hash-mining c library and its python binding.
C
65
star
4

zip-crc-cracker

Python
49
star
5

google-home-say

Get Google Home to say something
JavaScript
9
star
6

longcontest-visualizer-framework

TypeScript
8
star
7

marathon-kit

Python
7
star
8

atcoder-heuristic-contest-001

C++
6
star
9

forth-to-brainfuck

translator from a subset of forth to brainfuck
Forth
5
star
10

topcoder-marathon-match-100-same-color-pairs

https://community.topcoder.com/longcontest/?module=ViewProblemStatement&rd=17143&pm=14889
C++
5
star
11

procon26

ๅ…จๅ›ฝ้ซ˜็ญ‰ๅฐ‚้–€ๅญฆๆ กใƒ—ใƒญใ‚ฐใƒฉใƒŸใƒณใ‚ฐใ‚ณใƒณใƒ†ใ‚นใƒˆ
C++
5
star
12

atcoder-heuristic-contest-002

C++
4
star
13

AtCoderProblemsStatic

an API-server compatible with kenkoooo's AtCoderProblems
Python
4
star
14

codevs-for-student-2016

https://student.codevs.jp/
C++
2
star
15

tenka1-2021-spring

C++
2
star
16

brainfuck-self-interpreter

Brainfuck
2
star
17

markov-algorithm-interpreter

Python
2
star
18

atcoder-dos2unix-userscript

TypeScript
2
star
19

topcoder-marathon-match-rating-predictor

TypeScript
1
star
20

elementary-cellular-automaton-viewer

TypeScript
1
star
21

hill-cipher-implementation

Python
1
star
22

conway-script

an esoteric programming language based on the Conway's Game of Life
C++
1
star
23

topcoder-marathon-match-tco-2018-r1-roads-and-junctions

https://community.topcoder.com/longcontest/?module=ViewProblemStatement&compid=63555&rd=17153
C++
1
star
24

malbolge-interpreter

a simple interpreter for malbolge
Python
1
star
25

yandex-optimization-2018-round-1

TypeScript
1
star
26

brainfuck-debugger

Python
1
star
27

isucon8-final

Python
1
star
28

isucon-2017-qual

Python
1
star
29

min-caml-fsharp-whitespace

F#
1
star
30

bckw-interpreter

An interpreter of BCKW combinators.
Haskell
1
star
31

cp-unspoiler

TypeScript
1
star
32

lisp-to-unlambda

a translator from Lisp to Unlambda, based on the translator to Lazy K written by Ben Rudiak-Gould
Scheme
1
star
33

codingame-hypersonic

https://www.codingame.com/contests/hypersonic
C++
1
star
34

conways-game-of-life-viewer

TypeScript
1
star
35

atcoder-shojin-moving-average

TypeScript
1
star
36

whitespace-translater

translate the whitespace-language and an assembly-language, on browser
JavaScript
1
star
37

and-not-regex-engine

a regex engine with AND operator and NOT operator
Rust
1
star
38

shoujin-slack-notifier

Python
1
star
39

self-executable-piet-generator

generates something like self-extracting archive for Piet
Perl
1
star
40

topcoder-marathon-match-repository-template

Makefile
1
star
41

liquid-types-example

F#
1
star
42

topcoder-java-arena-docker

C++
1
star
43

topcoder-marathon-match-tco-2018-poland-map-recoloring

https://community.topcoder.com/tc?module=MatchDetails&rd=17149
Java
1
star