import hashlib
import struct

SealedRecord = bytes([
    13, 86, 51, 68, 18, 110, 68, 15, 54, 61,
    236, 94, 135, 202, 213, 182, 4, 1, 182, 181,
    150, 228, 184, 126, 121, 224, 236, 220, 7, 82,
    153, 251, 179, 104, 0, 87, 32, 34, 3, 60,
    166, 96, 124, 50, 253, 31, 124, 179, 220, 157,
    120, 115, 19, 47, 96, 11
])

TrueSeal = 15682021040575554950

def try_mark(mark):
    # C# BitConverter.GetBytes(ulong) is 8 bytes little-endian
    mark_bytes = struct.pack('<Q', mark)
    array = hashlib.sha256(mark_bytes).digest()
    
    array2 = bytearray(len(SealedRecord))
    i = 0
    num = 0
    
    while i < len(SealedRecord):
        array3 = array + struct.pack('<i', num)
        array4 = hashlib.sha256(array3).digest()
        num2 = 0
        while num2 < len(array4) and i < len(SealedRecord):
            array2[i] = SealedRecord[i] ^ array4[num2]
            num2 += 1
            i += 1
        num += 1
        
    # Check if the decrypted result is fully readable text
    if all(32 <= b < 127 for b in array2):
        return array2.decode('ascii')
    return None

print("Testing TrueSeal (15682021040575554950)...")
res = try_mark(TrueSeal)
if res:
    print("SUCCESS! THE FLAG IS:")
    print(res)
else:
    print("TrueSeal didn't work. Brute-forcing 0 to 100,000 just in case...")
    for m in range(0, 100001):
        res = try_mark(m)
        if res:
            print("SUCCESS! THE FLAG IS:")
            print(res)
            break

