1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//! # RustiCG
//! [LattiCG](https://github.com/mjtb49/LattiCG) rewritten in Rust with a focus on speed and usability.
//!
//! Reverses possible internal seeds of an LCG using a system of inequalities on the output of random calls.<br>
//! Currently only Java's java.util.Random class is implemented, but other LCGs can be added easily.
//!
//! ### Example
//! ```rust
//! use rusticg::reversal::dynamic_program::{DynamicProgram, Invertible, ReversalError};
//! use rusticg::reversal::java;
//! use rusticg::reversal::java::java_random;
//! use rusticg::util::{Random, JAVA};
//!
//! fn main() -> Result<(), ReversalError> {
//! let mut program = DynamicProgram::create(JAVA);
//!
//! // nextInt() == 0
//! program.add(java::next_int().equal_to(0)?)?;
//!
//! // nextFloat() <= 0.5
//! program.add(java::next_float().less_than_eq(0.5)?)?;
//!
//! // nextInt(16) == 2
//! program.add(java::next_bound_int(16)?.equal_to(2)?)?;
//!
//! // Ignore one call, e.g. an unknown nextInt() call
//! program.skip(1);
//!
//! // nextInt(4) != 1
//! program.add_filter(java::next_bound_int(4)?.equal_to(1)?.invert())?;
//!
//! let mut iterator = program.reverse();
//!
//! for _ in 0..25 {
//! let mut random = Random::of_seed(JAVA, iterator.next().unwrap());
//! let r = &mut random;
//!
//! assert_eq!(java_random::next_int(r), 0);
//! assert!(java_random::next_float(r) <= 0.5);
//! assert_eq!(java_random::next_bound_int(r, 16), 2);
//! java_random::next_int(r); // ignore one call
//! assert_ne!(java_random::next_int(r), 1);
//! }
//!
//! Ok(())
//! }
//! ```
/// Structs and functions related to reversing seeds.
/// Utility structs and functions.