Skip to content

Instantly share code, notes, and snippets.

@lincoln-lm
Last active June 3, 2026 17:01
Show Gist options
  • Select an option

  • Save lincoln-lm/c16e1dd27532c41941fa239010b156b3 to your computer and use it in GitHub Desktop.

Select an option

Save lincoln-lm/c16e1dd27532c41941fa239010b156b3 to your computer and use it in GitHub Desktop.
Recovers an initial state from two consecutive XDRNG outputs
q = 0xEB2E
a = 0x343FD
c = 0x269EC3
F = -0x229108
p = 3
p_inv = pow(p, -1, q)
def find_seeds(output_0, output_1):
base_solution = (((q * (output_1 - a * output_0) + F) >> 16) * p_inv) % q
# -0x9cc9 \equiv 0x4e65 (mod q)
for d_offset in (-0x9CC9, 0, 0x4E65, 0xEB2E):
candidate = base_solution + d_offset
if not 0 <= candidate < 0x10000:
continue
full_state = candidate | (output_0 << 16)
if (((full_state * a + c) >> 16) & 0xFFFF) == output_1:
yield full_state
import random
for _ in range(10000000):
seed = random.getrandbits(32)
output_0 = (seed >> 16) & 0xFFFF
output_1 = ((seed * a + c) >> 16) & 0xFFFF
assert seed in find_seeds(output_0, output_1), hex(seed)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment