Skip to main content

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() and offset_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 values
  • submit_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) – where n is number of 32-bit steps
  • offset_64(n) – where n is 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.

Metadata

Release files for extendedrandcrack 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for extendedrandcrack 1.0.0
File Size Uploaded
extendedrandcrack-1.0.0.tar.gz 7.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for extendedrandcrack 1.0.0
File Interpreter ABI Platform
extendedrandcrack-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 13.2 kB

Release files / extendedrandcrack-1.0.0.tar.gz

Download URL extendedrandcrack-1.0.0.tar.gz
Size 7.4 kB
Tags Source
SHA-256 checksum
How to use checksums
a6ad764dbb54e6a257cfa8f6d676f04b55d90984ef85f201c1e8ae4174ed6f44
BLAKE2b-256 checksum
How to use checksums
b8ebe96638e8f67b3a0a5f5c7c81d208d6a17f067bc3ad6c44f55f1563413b7f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release files / extendedrandcrack-1.0.0-py3-none-any.whl

Download URL extendedrandcrack-1.0.0-py3-none-any.whl
Size 5.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
feed60573d4f031900a379a7f4f90be27d839d975a85da9c9459ea60fb9c4b2e
BLAKE2b-256 checksum
How to use checksums
1fe751fb2116429fd775a5a24da6635ee55dfbe29fc1b2a35a26487b3929b123
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page