cleanup
This commit is contained in:
28
2026/cscg/rev/gloomweaver/find_hash.py
Normal file
28
2026/cscg/rev/gloomweaver/find_hash.py
Normal file
@@ -0,0 +1,28 @@
|
||||
# find_hash.py — find a flag that passes the checksum
|
||||
import struct
|
||||
|
||||
def compute_hash(flag_bytes):
|
||||
eax = 0x65
|
||||
for b in flag_bytes:
|
||||
ecx = eax & 0xFFFFFFFF
|
||||
edx = eax & 0xFF # dl only
|
||||
ecx = (ecx << 6) & 0xFFFFFFFF
|
||||
edx = (edx >> 6) & 0xFF
|
||||
eax = (eax + ecx) & 0xFFFFFFFF
|
||||
eax = (eax + edx) & 0xFFFFFFFF
|
||||
eax ^= b
|
||||
return eax & 0xFF
|
||||
|
||||
prefix = b"CTF{th1s_"
|
||||
suffix = b"}"
|
||||
# 64 bytes total: 9 prefix + 54 middle + 1 suffix
|
||||
# Try different last middle byte
|
||||
for last in range(0x21, 0x7F):
|
||||
middle = b"A" * 53 + bytes([last])
|
||||
flag = prefix + middle + suffix
|
||||
assert len(flag) == 64
|
||||
h = compute_hash(flag)
|
||||
if h == 0x0C:
|
||||
print(f"Found: {flag.decode()}")
|
||||
print(f"Hash: 0x{h:02x}")
|
||||
break
|
||||
Reference in New Issue
Block a user