Skip to content

Instantly share code, notes, and snippets.

@bbayles
Created November 16, 2025 13:43
Show Gist options
  • Select an option

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

Select an option

Save bbayles/d8a75281b9e7cd7e5ae5b0e9085379e7 to your computer and use it in GitHub Desktop.
Unscramble the special names for Need For Speed: High Stakes (PlayStation)
def scramble_01(data):
n = len(data)
return bytes(
sum(((data[y] >> x) & 1) << y for y in range(n)) for x in range(n)
)
def scramble_02(data):
n = len(data)
local_8 = bytearray(n)
output = bytearray(n)
for i in range(n):
inverted_byte = (~data[i]) & 0xFF
local_8[i] = inverted_byte
output[i] = inverted_byte
for i in range(n):
bit_from_local_0 = (local_8[0] >> i) & 1
bit_from_local_i = (local_8[i] >> i) & 1
mask = 1 << i
output[0] = (output[0] & ~mask) | (bit_from_local_i << i)
output[i] = (output[i] & ~mask) | (bit_from_local_0 << i)
for i in range(1, n):
j = i - 1
bit_j_from_local = (local_8[i] >> j) & 1
bit_0_from_local = (local_8[i] >> 0) & 1
mask_0 = 1 << 0
mask_j = 1 << j
cleared_val = output[i] & ~mask_0 & ~mask_j
new_val = cleared_val | (bit_j_from_local << 0) | (bit_0_from_local << j)
output[i] = new_val
return bytes(output)
if __name__ == '__main__':
for scrambled_data, function in (
(b'\x0c\x09\x03\x12\x08\x1e\x1f\x00', scramble_01),
(b'\x12\x1a\x36\x13\x0c\x3e\x3f\x00', scramble_01),
(b'\x25\x09\x11\x36\x29\x3e\x3f\x00', scramble_01),
(b'\xcd\x99\x88\xd7\xbf\xbb\xbf\xff', scramble_02),
(b'\x87\xdf\xdf\xab\x9d\x8f\xd8\xff', scramble_02),
):
print(function(scrambled_data).decode().strip('\0'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment