Skip to content

Instantly share code, notes, and snippets.

@bbayles
Created November 27, 2025 19:51
Show Gist options
  • Select an option

  • Save bbayles/056aa3717b262c4968d888ab11f986b5 to your computer and use it in GitHub Desktop.

Select an option

Save bbayles/056aa3717b262c4968d888ab11f986b5 to your computer and use it in GitHub Desktop.
Generate "unlock everything" codes for Michelin Rally Masters (PlayStation)
CODE_ALPHABET = "BCDFGHJKLMNPQRSTVWXZ0123456789%?"
def to_u32(x):
return x & 0xFFFFFFFF
def prng(state):
while True:
a = to_u32(state + 0x1835A17F) >> 16
b = to_u32(state << 16) ^ a
c = to_u32(state + 0x1835A17F) ^ b
d = to_u32((state + c) * 8)
state = to_u32(d + ((d >> 13) & 7))
yield (b & 0x7FFFFFFF) | a
def calculate_checksums(ascii_values):
a, b, c, d, e, f, g, h, i, j = ascii_values[:10]
# Checksum 1: Simple sum mod 32
k = (a + b + c + d + e + f + g + h + i + j) % 32
# Checksum 2: Alternating addition/subtraction mod 32
l = ((a + b) - c + d - e + f - g + h - i + j) % 32
# Checksum 3: XOR of ORed pairs, masked to 5 bits
m = ((a | b) ^ (c | d) ^ (e | f) ^ (g | h) ^ (i | j)) & 0x1F
return k, l, m
def generate_code(seed_index):
# The first character corresponds to the seed.
chars = [CODE_ALPHABET[seed_index]]
# Generate PRNG sequence from the given seed index.
prng_values = prng(seed_index)
# We want to have all bits set in the unlock flags, so the next 9 characters
# need to produce values of 1 when matched with their indexes in the shifted
# alphabet.
target_offsets = [1, 1, 1, 1, 1, 1, 1, 1, 1]
for pv, offset in zip(prng_values, target_offsets):
chars.append(CODE_ALPHABET[(pv + offset) % 32])
# Generate the checksum values.
ascii_vals = [ord(c) for c in chars]
k, l, m = calculate_checksums(ascii_vals)
chars.extend([CODE_ALPHABET[k], CODE_ALPHABET[l], CODE_ALPHABET[m]])
return "".join(chars)
if __name__ == "__main__":
for i in range(32):
print(generate_code(i))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment