Skip to content

Instantly share code, notes, and snippets.

@moriyoshi
Created September 8, 2019 22:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moriyoshi/f08d5f8feeb7509e51d6cfe7d1e8ef98 to your computer and use it in GitHub Desktop.
Save moriyoshi/f08d5f8feeb7509e51d6cfe7d1e8ef98 to your computer and use it in GitHub Desktop.
Recover a XP product key from the registry
import math
# HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\DigitalProductId
# offset from 28 (0x1c) to 43 (0x2b)
b = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
digits = "BCDFGHJKMPQRTVWXY2346789"
def base24(b):
v = sum((256 ** i) * c for i, c in enumerate(b))
for _ in range(int(math.ceil(math.log(256) * len(b) / math.log(24)))):
yield digits[v % 24]
v //= 24
print(''.join(('-' if i % 5 == 0 else '') + c for i, c in enumerate(reversed(list(base24(b))[:25])))[1:])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment