#!/usr/bin/env python3
# Extract the flag from the obfuscated baby.py

def G0g0sQu1D_116510(a, b):
    """The main XOR function"""
    return a ^ b

def g0GOsquiD(a, b):
    """Combines two XOR results"""
    return a ^ b

def gOg0sQuId(a, b):
    """Another XOR variant"""
    return a ^ b

# Extract the prompt message by decoding the gOg0sQuId calls
# Looking at the pattern in baby.py around the input prompt

# The success message is printed if validation passes
# Let's extract character codes from the success message at line 924

success_chars = [
    gOg0sQuId(g0GOsquiD(G0g0sQu1D_116510(30, 1672), G0g0sQu1D_116510(5892, 4876)), g0GOsquiD(G0g0sQu1D_116510(6828, 5539), G0g0sQu1D_116510(7367, 4405))),
    gOg0sQuId(g0GOsquiD(G0g0sQu1D_116510(2498, 995), G0g0sQu1D_116510(3472, 226)), g0GOsquiD(G0g0sQu1D_116510(3181, 117), G0g0sQu1D_116510(5268, 8074))),
    gOg0sQuId(g0GOsquiD(G0g0sQu1D_116510(321, 5917), G0g0sQu1D_116510(8925, 8618)), g0GOsquiD(G0g0sQu1D_116510(11826, 8950), G0g0sQu1D_116510(717, 7021))),
    gOg0sQuId(g0GOsquiD(G0g0sQu1D_116510(3589, 2808), G0g0sQu1D_116510(4790, 8128)), g0GOsquiD(G0g0sQu1D_116510(3892, 1322), G0g0sQu1D_116510(7581, 7698))),
    gOg0sQuId(g0GOsquiD(G0g0sQu1D_116510(12244, 8365), G0g0sQu1D_116510(3981, 2697)), g0GOsquiD(G0g0sQu1D_116510(5734, 332), G0g0sQu1D_116510(6790, 1932))),
]

print("Success message first 5 chars:")
for i, code in enumerate(success_chars):
    if code < 256:
        print(f"Char {i}: {code} = '{chr(code)}'")
    else:
        print(f"Char {i}: {code} (too large)")

# The input is validated against something stored in the nested functions
# Let's see if we can extract the actual flag by analyzing the pattern

# Looking at the main validation, it seems like the flag should be
# extracted by analyzing the gOg0sQuId XOR patterns

# Let me try a different approach - simulate the validation to reverse engineer the flag
print("\nTrying to extract the validation mechanism...")

# Reload the actual baby.py and parse it
import re

with open('baby.py', 'r') as f:
    content = f.read()

# Find all G0g0sQu1D_116510 calls that create the success message
# The success message appears to be built from a list of gOg0sQuId calls

success_message_match = re.search(r'print\(g0gosqu1D\(\[(.*?)\],', content, re.DOTALL)
if success_message_match:
    print("\nFound success message pattern (first 500 chars):")
    print(success_message_match.group(1)[:500])
