Giter VIP home page Giter VIP logo

foresight's Introduction

Foresight

foresight is a python library for predicting the output of random number generators across a variety of platforms and languages including:

  • glibc
  • MSVC
  • PHP
  • Java
  • MySQL

This repository also contains a simple wrapper (called foresee) around this library that provides a CLI.

Installation

To install foresight, clone this repository and run python setup.py install.

Library Usage

The library is divided into subpackages for each supported platform. These subpackages then provide submodules for each supported function. For example,the following sample will predict the output of the glibc rand_r from some prior outputs:

from foresight.glibc import rand_r

prior_outputs = [int(i) for i in input().split()]
future_outputs = rand_r.from_outputs(prior_outputs)

for output in future_outputs:
    print(output)

Generally, each module provides the following functions:

  • from_seed(seed): get a generator to the future values returned by the RNG when seeded with the given value.

  • from_outputs(prev_values): attempt to predict the internal state of the RNG from the given prior outputs. If successful, returns a generator to the future values returned by the RNG.

CLI Usage

Command line usage of the library has the following general form:

foresee <platform> <function> [<options>]

For example, the above script is equivalent to the following foresee command:

foresee glibc rand_r -o <the prior outputs>

By default, an infinite stream is generated. The output may be limited to the next N outputs with -c N.

Tests

Tests can be run with nose by first installing the package with pip install nose, and then running nosetest in the project root.

License

This project is licensed under the terms of the MIT license. See the LICENSE file for details

Contributing

Keeping in mind that this project is still fairly unstable, contributions are welcome.

foresight's People

Contributors

alschwalm avatar jgeralnik avatar jwilk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

foresight's Issues

How to run foresight?

i want to run a example
$ python predict_captcha.py
but it doesn't work:
Traceback (most recent call last): File "predict_captcha.py", line 12, in <module> from foresight.php import rand File "build/bdist.linux-x86_64/egg/foresight/php/rand.py", line 6, in <module> File "/usr/local/lib/python2.7/dist-packages/foresight-0.1-py2.7.egg/foresight/glibc/random.py", line 82 yield from gen SyntaxError: invalid syntax
can you tell me how to run this in the right way?

Installation problem

Hello, I'm new here and in programming (I'm still a student) so maybe I'm doing something wrong... I cloned the folder trough the URL, but when I try to run the setup the terminal windows appear and disappear and then nothing happens... (I also tried to launch it with Python 3.6) Thank you very much for the help!

glibc predicting output

I have a simple program that generates numbers between 1-200. Is it possible to use the foresight to predict my numbers that are between 1-200?

foresight.glibc does not work, especially the example in the README.md

On macOS using Python 3.7.3:
from foresight.glibc import rand_r def getSeed(username): seed = 0 for letter in username: seed += 2*(ord(letter))+ 1 return seed % 50 predictFuture = lambda seed: rand_r.from_seed(seed) if __name__ == '__main__': gen = predictFuture(33) for i in range(13): print(next(gen))
The output is:
688604985 1404424582 148037270 942075973 2024509987 830516112 751824416 482053972 1397384927 230775254 1724150635 561277606 1569257928
For rand_r in C++:
#include <iostream> #include <cstdlib> #include <stdlib.h> using namespace std; int main(){ unsigned int c = 33; for ( size_t i = 0; i<13; i++){ cout << rand_r(&c) << endl; } return 0; }
Returns the following output:
554631 731748629 2007844881 290886009 1248372691 484586447 1186425305 864438740 895031225 1814334987 1407822756 302237446 905929767
(Never mind it works for glibc on Linux, however implementing a solution for Mac would be great)

Crash on startup: IndexError: list index out of range

$ foresee php linux rand -o 60 16 19 30 44 3 50 51 54 42 61 5 41 16 33 60

Warning: Some predictions my be incorrect.

Traceback (most recent call last):
  File "/usr/local/bin/foresee", line 9, in <module>
    load_entry_point('foresight==0.1', 'console_scripts', 'foresee')()
  File "/usr/local/lib/python3.4/dist-packages/foresight-0.1-py3.4.egg/foresight/foresee.py", line 212, in main
  File "/usr/local/lib/python3.4/dist-packages/foresight-0.1-py3.4.egg/foresight/foresee.py", line 90, in handle_php
  File "/usr/local/lib/python3.4/dist-packages/foresight-0.1-py3.4.egg/foresight/foresee.py", line 15, in print_from_gen
  File "/usr/local/lib/python3.4/dist-packages/foresight-0.1-py3.4.egg/foresight/php/rand.py", line 70, in from_outputs
  File "/usr/local/lib/python3.4/dist-packages/foresight-0.1-py3.4.egg/foresight/glibc/random.py", line 79, in generate_values
    
  File "/usr/local/lib/python3.4/dist-packages/foresight-0.1-py3.4.egg/foresight/glibc/random.py", line 72, in inner
    share state.
IndexError: list index out of range

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.