Predict Python's random module outputs, extended with 64-bit support and state rewind/advance
Project description
Extended RandCrack – Advanced Python random module cracker / predictor
This library is based on randcrack but provides extended functionality, including support for 64-bit number submission and 64-bit state offsetting, making it even more powerful for reverse-engineering or simulating Python's random module.
What It Does
This script clones Python’s built-in random number generator based on the Mersenne Twister. After observing 624 outputs of 32-bit integers, it reconstructs the internal state and can then:
- Predict all future outputs
- Predict past outputs
- Handle 64-bit values directly with
submit_64()andoffset_64()
⚠️ The Mersenne Twister is not cryptographically secure. Do not use it for secure cryptographic applications. More info
Installation
pip install extendedrandcrack
Usage
You must provide exactly 624 32-bit integers or 312 64-bit integers to reconstruct the RNG state. Use either:
submit(value)– for 32-bit valuessubmit_64(value)– for 64-bit values (automatically splits into two 32-bit chunks)
Basic Example (32-bit)
import random
import time
from extendedrandcrack import RandCrack
random.seed(time.time())
rc = RandCrack()
for \_ in range(624):
rc.submit(random.getrandbits(32))
print("Random:", random.getrandbits(32))
print("Predicted:", rc.predict_getrandbits(32))
Using 64-bit Submissions
import random
from extendedrandcrack import RandCrack
rc = RandCrack()
random.seed(12345)
values = [random.getrandbits(64) for _ in range(312)]
for v in values:
rc.submit_64(v)
print("Next random 64-bit value:")
high = rc.predict_getrandbits(32)
low = rc.predict_getrandbits(32)
predicted = (high << 32) | low
print(predicted)
Predicting Past Outputs
You can go back in time using:
offset(n)– wherenis number of 32-bit stepsoffset_64(n)– wherenis number of 64-bit steps
Negative values go back, positive values move forward.
Example – Rewind and Predict
import random
from extendedrandcrack import RandCrack
random.seed(42)
original = [random.getrandbits(32) for _ in range(10)]
rc = RandCrack()
for \_ in range(624):
rc.submit(random.getrandbits(32))
rc.offset(-624) # rewind to where we started
rc.offset(-10) # rewind before the known sequence
print("Original:", original)
print("Recovered:", [rc.predict_getrandbits(32) for _ in range(10)])
Accuracy Note on High-level Functions
The following prediction methods are available:
predict_getrandbits(k)predict_randbelow(n)predict_randrange(start, stop[, step])predict_randint(a, b)predict_choice(seq)predict_random()
⚠️ randbelow(), randint(), randrange(), and choice() may consume more than one random number per call, so rewinding past these calls is imprecise. Use getrandbits() or random() for exact state tracking.
Testing
The script includes a test block that checks both forward and backward prediction across 1000 values and asserts 100% accuracy.
License
MIT. Based on original randcrack by tna0y, extended for 64-bit support and improved state handling.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file extendedrandcrack-1.0.0.tar.gz.
File metadata
- Download URL: extendedrandcrack-1.0.0.tar.gz
- Upload date:
- Size: 7.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a6ad764dbb54e6a257cfa8f6d676f04b55d90984ef85f201c1e8ae4174ed6f44
|
|
| MD5 |
49d1641d67334d2c7c498c699c8b5804
|
|
| BLAKE2b-256 |
b8ebe96638e8f67b3a0a5f5c7c81d208d6a17f067bc3ad6c44f55f1563413b7f
|
File details
Details for the file extendedrandcrack-1.0.0-py3-none-any.whl.
File metadata
- Download URL: extendedrandcrack-1.0.0-py3-none-any.whl
- Upload date:
- Size: 5.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
feed60573d4f031900a379a7f4f90be27d839d975a85da9c9459ea60fb9c4b2e
|
|
| MD5 |
8841e02d6c1154a74e79ecfbeadc101b
|
|
| BLAKE2b-256 |
1fe751fb2116429fd775a5a24da6635ee55dfbe29fc1b2a35a26487b3929b123
|