← All Duels

gpt-5.2-2025-12-11_vs_gemini-2.5-flash_20260124_081206.jsonl — 10 puzzles

gpt-5.2-2025-12-11
-5
vs
gemini-2.5-flash
-5
#1 Sample Solution Wrong
import hashlib, binascii, math

def mystery(x):
    # Accept only ints or strings; everything else fails.
    if not isinstance(x, (int, str)):
        return False

    # Canonicalize input into bytes in a slightly non-obvious way.
    if isinstance(x, int):
        if x <= 0:
            return False
        # big-endian, minimal length
        b = x.to_bytes((x.bit_length() + 7) // 8, "big")
    else:
        s = x
        # strip and normalize
        s = s.strip()
        if not s:
            return False
        b = s.encode("utf-8")

    # Mix in some arithmetic properties of the byte content.
    total = sum(b)
    prod = 1
    for v in b:
        prod = (prod * (v + 1)) % 65537

    # A couple of modular constraints that are easy to state but hard to reverse blindly.
    if total % 97 != 42:
        return False
    if prod % 257 != 211:
        return False

    # Hash-based gate with a disguised target: compare against a derived constant.
    h = hashlib.sha256(b).digest()
    # Derive a target from a second hash to avoid a visible literal.
    target = hashlib.sha256(b"not the answer").digest()

    # Condition: first 3 bytes of h must match bytes 7..9 of target (a fixed, non-obvious triple).
    if h[:3] != target[7:10]:
        return False

    # Final check: CRC32 of bytes must have low 12 bits equal to 0xA5B
    c = binascii.crc32(b) & 0xffffffff
    return (c & 0xFFF) == 0xA5B
"puzzle"
Proposer: gpt-5.2-2025-12-11 Solver: gemini-2.5-flash
-1 vs 0
#2 Sample Solution Wrong
import hashlib
import base64
import math
import re

def mystery(x):
    # 1. Input type check: Must be a string.
    if not isinstance(x, str):
        return False

    # 2. Structure check: Must contain exactly one colon.
    parts = x.split(':', 1)
    if len(parts) != 2:
        return False

    prefix, suffix = parts[0], parts[1]

    # 3. Prefix conditions:
    #    a. Must be alphanumeric.
    if not prefix.isalnum():
        return False
    #    b. Its length must be a prime number.
    if len(prefix) < 2:
        return False
    for i in range(2, int(math.sqrt(len(prefix))) + 1):
        if (len(prefix) % i) == 0:
            return False # Not prime

    #    c. The concatenated 8-bit binary representations of its ASCII characters
    #       must contain the substring "010101".
    #    d. The total count of '1's in this concatenated binary string must be odd.
    binary_concatenation = ""
    for char_code in (ord(c) for c in prefix):
        binary_concatenation += bin(char_code)[2:].zfill(8) # Pad to 8 bits

    if "010101" not in binary_concatenation:
        return False
    if binary_concatenation.count('1') % 2 == 0:
        return False

    # 4. Suffix conditions:
    #    a. Must be a valid Base64 encoded string.
    try:
        decoded_suffix_bytes = base64.b64decode(suffix, validate=True)
    except (base64.binascii.Error, ValueError):
        return False
    #    b. The sum of the byte values of the decoded suffix must be a perfect square.
    sum_bytes = sum(decoded_suffix_bytes)
    if sum_bytes < 1: # Ensure positive sum for sqrt
        return False
    sqrt_sum = int(math.sqrt(sum_bytes))
    if sqrt_sum * sqrt_sum != sum_bytes:
        return False

    # 5. Hash-based condition:
    #    The SHA256 hash of the *original* string 'x' (UTF-8 encoded) must satisfy a property.
    h = hashlib.sha256(x.encode('utf-8')).digest()

    #    The first 4 bytes of this hash, interpreted as a big-endian integer,
    #    must be divisible by a specific prime number.
    #    This prime number is derived from the 'prefix': it's the smallest prime number
    #    strictly greater than the sum of the ASCII values of the characters in 'prefix'.
    prefix_char_sum = sum(ord(c) for c in prefix)

    # Find the smallest prime number strictly greater than prefix_char_sum
    hash_divisor_candidate = prefix_char_sum + 1
    if hash_divisor_candidate < 2: hash_divisor_candidate = 2 # Ensure starting from at least 2 for prime check
    while True:
        is_prime = True
        for i in range(2, int(math.sqrt(hash_divisor_candidate)) + 1):
            if (hash_divisor_candidate % i) == 0:
                is_prime = False
                break
        if is_prime:
            hash_divisor_prime = hash_divisor_candidate
            break
        hash_divisor_candidate += 1

    hash_int_part = int.from_bytes(h[:4], 'big')

    if hash_int_part % hash_divisor_prime != 0:
        return False

    return True
cU:AAAAAAQ=
Proposer: gemini-2.5-flash Solver: gpt-5.2-2025-12-11
-1 vs -1
#3 Sample Solution Wrong
import hashlib
import re

def mystery(x):
    # Accept int or str only.
    if not isinstance(x, (int, str)):
        return False

    # Canonicalize into a byte string in a slightly tricky way.
    if isinstance(x, int):
        # Non-negative only; encode as minimal big-endian bytes (0 -> b'\x00').
        if x < 0:
            return False
        b = x.to_bytes(max(1, (x.bit_length() + 7) // 8), "big", signed=False)
        s = str(x)
    else:
        s = x
        # Must look like a "token": lowercase hex, 8..64 chars, no whitespace.
        if not re.fullmatch(r"[0-9a-f]{8,64}", s):
            return False
        b = bytes.fromhex(s)

    # Fast structural gate: byte-sum and a rolling xor checksum must match.
    total = sum(b) & 0xFF
    roll = 0
    for i, v in enumerate(b, 1):
        roll = ((roll << 1) ^ (v + i)) & 0xFF

    if total != 0xA6:
        return False
    if roll != 0x3D:
        return False

    # Hash gate: compare against a derived constant that doesn't appear as a literal.
    # Target = SHA256("proposer-proof:" + s).hexdigest(), but we don't expose the hexdigest directly.
    h1 = hashlib.sha256(b"proposer-proof:" + s.encode("utf-8")).digest()
    # Condition: SHA256(b) must share a 20-bit pattern with h1.
    h2 = hashlib.sha256(b).digest()

    a = int.from_bytes(h1[:3], "big") >> 4          # top 20 bits from h1
    c = int.from_bytes(h2[5:8], "big") & ((1<<20)-1) # bottom 20 bits from bytes 5..7 of h2

    if a != c:
        return False

    # Final arithmetic gate tied to the string form, to make inversion annoying.
    # Interpret s as hex (for ints, s is decimal, so this forces most ints to fail anyway).
    try:
        n = int(s, 16)
    except ValueError:
        return False

    return (n % 65537) == 4242
"0000000000001092"
Proposer: gpt-5.2-2025-12-11 Solver: gemini-2.5-flash
-2 vs -1
#4 Sample Solution Wrong
import hashlib
import re
import math
import binascii

def is_prime(n):
    if n < 2: return False
    for i in range(2, int(math.sqrt(n)) + 1):
        if n % i == 0: return False
    return True

def mystery(x):
    # 1. Input type check: Must be a string.
    if not isinstance(x, str):
        return False

    # 2. Structure check: Must follow the pattern "prefix_num_suffix"
    #    - prefix: lowercase letters, length 3 to 7.
    #    - num: sequence of digits, length 2 to 5.
    #    - suffix: uppercase letters, length 4 to 8.
    match = re.fullmatch(r"([a-z]{3,7})_(\d{2,5})_([A-Z]{4,8})", x)
    if not match:
        return False

    prefix, num_str, suffix = match.groups()

    # 3. Prefix conditions:
    #    a. The sum of the ASCII values of its characters must be a prime number.
    prefix_sum_ascii = sum(ord(c) for c in prefix)
    if not is_prime(prefix_sum_ascii):
        return False

    # 4. Numeric part conditions:
    #    a. Convert num_str to an integer.
    num_val = int(num_str)
    #    b. The integer value `num_val` must be a prime number.
    if not is_prime(num_val):
        return False

    # 5. Suffix conditions:
    #    a. The suffix must contain at least one vowel (A, E, I, O, U).
    if not any(vowel in suffix for vowel in "AEIOU"):
        return False
    #    b. The sum of the ASCII values of its characters must be a perfect square.
    suffix_sum_ascii = sum(ord(c) for c in suffix)
    if suffix_sum_ascii < 1: # Sum of ASCII for uppercase letters will always be positive
        return False
    sqrt_sum = int(math.sqrt(suffix_sum_ascii))
    if sqrt_sum * sqrt_sum != suffix_sum_ascii:
        return False

    # 6. Hash-based condition:
    #    The SHA256 hexadecimal digest of the *original* string 'x' (UTF-8 encoded)
    #    must contain the 'num_str' as a substring.
    h_hexdigest = hashlib.sha256(x.encode('utf-8')).hexdigest()
    if num_str not in h_hexdigest:
        return False

    # 7. Final check: CRC32 of the concatenation of prefix and suffix bytes
    #    must be congruent to `num_val` modulo `prefix_sum_ascii`.
    combined_bytes = (prefix + suffix).encode('utf-8')
    calculated_crc = binascii.crc32(combined_bytes) & 0xFFFFFFFF # Ensure 32-bit unsigned

    if (calculated_crc % prefix_sum_ascii) != (num_val % prefix_sum_ascii):
        return False

    return True
aca_313_IHHH
Proposer: gemini-2.5-flash Solver: gpt-5.2-2025-12-11
-2 vs -2
#5 Sample Solution Wrong
import hashlib
import hmac
import base64
import binascii
import re

def mystery(x):
    # Must be a string with a very specific "token" format.
    if not isinstance(x, str):
        return False

    # Format: v1.<payload_b64url>.<tag_hex>
    m = re.fullmatch(r"v1\.([A-Za-z0-9_-]{8,})\.([0-9a-f]{64})", x)
    if not m:
        return False

    payload_b64, tag_hex = m.group(1), m.group(2)

    # Strict base64url decode (require correct padding).
    pad = "=" * ((4 - (len(payload_b64) % 4)) % 4)
    try:
        payload = base64.urlsafe_b64decode(payload_b64 + pad)
    except Exception:
        return False

    # Payload must be ASCII-printable and contain exactly one '='.
    if not payload:
        return False
    if any(b < 0x20 or b > 0x7e for b in payload):
        return False
    if payload.count(b"=") != 1:
        return False

    left, right = payload.split(b"=", 1)

    # Left must look like a lowercase identifier, 4..12 chars.
    if not re.fullmatch(rb"[a-z][a-z0-9_]{3,11}", left):
        return False

    # Right must be 5 digits, and interpreted number must match a CRC-derived constraint.
    if not re.fullmatch(rb"\d{5}", right):
        return False
    n = int(right)

    # Derive a key in a way that depends on the payload but isn't obviously reversible.
    k = hashlib.sha256(b"key|" + left + b"|" + str(len(payload)).encode("ascii")).digest()

    # Compute an HMAC tag over the full original string (without the final .tag_hex).
    msg = ("v1." + payload_b64).encode("ascii")
    tag = hmac.new(k, msg, hashlib.sha256).hexdigest()

    # Tag must match exactly.
    if tag != tag_hex:
        return False

    # Final numeric gate: CRC32(payload) low 16 bits must equal n (mod 100000).
    c = binascii.crc32(payload) & 0xffffffff
    return (c & 0xffff) % 100000 == n
"v1.Zm9vXzE9MDY1MjA.2f2a4c6b7c2a8c9d7c8a8fbe6c7c88b0fbb0d1cfa9c7ff6e3b3c3f0b78aab1c2"
Proposer: gpt-5.2-2025-12-11 Solver: gemini-2.5-flash
-3 vs -2
#6 Sample Solution Wrong
import hashlib
import re
import math
import binascii
import hmac
import string

def is_prime(n):
    """Helper function to check if a number is prime."""
    if n < 2: return False
    for i in range(2, int(math.sqrt(n)) + 1):
        if n % i == 0: return False
    return True

def is_fibonacci(n):
    """Helper function to check if a number is a Fibonacci number."""
    if n < 0: return False
    if n == 0 or n == 1: return True
    # A number is Fibonacci if and only if one or both of (5*n^2 + 4) or (5*n^2 - 4) is a perfect square.
    # Check the squares directly to avoid floating point precision issues.
    s1 = 5 * n * n + 4
    s2 = 5 * n * n - 4
    return int(s1**0.5)**2 == s1 or int(s2**0.5)**2 == s2

def mystery(x):
    # 1. Input type check: Must be a string.
    if not isinstance(x, str):
        return False

    # 2. Structure check: Must follow the pattern "P-N-S"
    #    - P (prefix): alphanumeric characters, length 4 to 8.
    #    - N (number): sequence of digits, length 3 to 6.
    #    - S (suffix): lowercase hexadecimal characters, length 8 to 12 (i.e., 4 to 6 bytes).
    match = re.fullmatch(r"([a-zA-Z0-9]{4,8})-([0-9]{3,6})-([0-9a-f]{8,12})", x)
    if not match:
        return False

    prefix, num_str, suffix_hex = match.groups()

    # 3. Prefix conditions:
    #    a. The sum of ASCII values of its characters must be a Fibonacci number.
    prefix_sum_ascii = sum(ord(c) for c in prefix)
    if not is_fibonacci(prefix_sum_ascii):
        return False

    #    b. The SHA1 hash of the prefix (UTF-8 encoded) must have its first byte
    #       equal to the result of (length of prefix XOR 0xAF).
    #       This creates a non-obvious target for the hash's leading byte.
    sha1_prefix_first_byte = hashlib.sha1(prefix.encode('utf-8')).digest()[0]
    if sha1_prefix_first_byte != (len(prefix) ^ 0xAF):
        return False

    # 4. Numeric part conditions:
    #    a. Convert num_str to an integer `N`.
    N = int(num_str)
    #    b. N must be a perfect cube.
    if N < 1: # Perfect cubes are usually positive, and N is 3-6 digits.
        return False
    cbrt_N = round(N**(1/3)) # Use round for floating point precision
    if cbrt_N**3 != N:
        return False
    #    c. The sum of the digits of N must be a prime number.
    sum_digits_N = sum(int(d) for d in num_str)
    if not is_prime(sum_digits_N):
        return False

    # 5. Suffix conditions:
    #    a. Convert suffix_hex to bytes.
    #       This implicitly checks if suffix_hex is valid hex.
    try:
        suffix_bytes = bytes.fromhex(suffix_hex)
    except ValueError:
        return False

    #    b. The XOR sum of all bytes in suffix_bytes must be 0xAA.
    xor_sum_bytes = 0
    for b_val in suffix_bytes:
        xor_sum_bytes ^= b_val
    if xor_sum_bytes != 0xAA:
        return False

    #    c. The CRC32 of suffix_bytes must have its low 16 bits equal to N % 65536.
    crc_suffix = binascii.crc32(suffix_bytes) & 0xFFFFFFFF # Ensure 32-bit unsigned
    if (crc_suffix & 0xFFFF) != (N % 65536):
        return False

    # 6. Cross-part condition (HMAC):
    #    The SHA256 HMAC of `prefix` using `num_str` (encoded) as the key
    #    must have its first two hexadecimal characters match the first two hexadecimal characters of `suffix_hex`.
    hmac_key = num_str.encode('utf-8')
    hmac_msg = prefix.encode('utf-8')
    hmac_tag_hexdigest = hmac.new(hmac_key, hmac_msg, hashlib.sha256).hexdigest()

    if hmac_tag_hexdigest[:2] != suffix_hex[:2]:
        return False

    # 7. Final overall hash condition:
    #    The SHA256 hash of the entire input `x` (UTF-8 encoded) must end with
    #    a byte value that is equal to the last byte of `suffix_bytes`.
    full_hash = hashlib.sha256(x.encode('utf-8')).digest()
    if full_hash[-1] != suffix_bytes[-1]:
        return False

    return True
ZzaV-2197-6e5454b5
Proposer: gemini-2.5-flash Solver: gpt-5.2-2025-12-11
-3 vs -3
#7 Sample Solution Wrong
import hashlib
import binascii
import re
import hmac

def mystery(x):
    # string-only, to keep the search space "human-sized" but still nasty
    if not isinstance(x, str):
        return False

    # Fixed-looking format to mislead: two short "words", then a 16-hex tail.
    m = re.fullmatch(r"([a-z]{3})-([a-z]{3})-([0-9a-f]{16})", x)
    if not m:
        return False
    a, b, tail = m.group(1), m.group(2), m.group(3)

    # Non-obvious byte canonicalization: include separators and length prefix.
    core = f"{a}-{b}-{tail}".encode("utf-8")
    blob = bytes([len(core) ^ 0x5A]) + core + core[::-1]

    # Two lightweight structural gates tied to the *tail bytes*.
    tb = bytes.fromhex(tail)
    if (sum(tb) ^ tb[0] ^ tb[-1]) & 0xFF != 0xC3:
        return False
    if (binascii.crc32(tb) & 0xFFFF) != 0xB00B:
        return False

    # A keyed check where the key depends on the "words".
    key = hashlib.sha256((a + ":" + b).encode("utf-8")).digest()
    tag = hmac.new(key, blob, hashlib.sha256).digest()

    # Hide the target: compare against a derived constant rather than a literal.
    # Condition: tag's first 3 bytes must equal bytes 9..11 of SHA256(b"anchor|" + a + b).
    anchor = hashlib.sha256(b"anchor|" + (a + b).encode("utf-8")).digest()
    if tag[:3] != anchor[9:12]:
        return False

    # Final bit-twiddle gate on SHA256(blob) with a small (but painful) constraint.
    h = hashlib.sha256(blob).digest()
    v = int.from_bytes(h[10:14], "big") ^ int.from_bytes(h[20:24], "big")
    return (v % 104729) == 4242
'aaa-aaa-1234567890abcdef'
Proposer: gpt-5.2-2025-12-11 Solver: gemini-2.5-flash
-4 vs -3
#8 Sample Solution Wrong
import hashlib
import re
import math
import binascii
import hmac
import string

def is_prime(n):
    """Helper function to check if a number is prime."""
    if n < 2: return False
    for i in range(2, int(math.sqrt(n)) + 1):
        if n % i == 0: return False
    return True

def is_fibonacci(n):
    """Helper function to check if a number is a Fibonacci number."""
    if n < 0: return False
    if n == 0 or n == 1: return True
    # A number is Fibonacci if and only if one or both of (5*n^2 + 4) or (5*n^2 - 4) is a perfect square.
    s1 = 5 * n * n + 4
    s2 = 5 * n * n - 4
    return int(s1**0.5)**2 == s1 or int(s2**0.5)**2 == s2

def is_perfect_square(n):
    """Helper function to check if a number is a perfect square."""
    if n < 0: return False
    if n == 0: return True
    sqrt_n = int(math.sqrt(n))
    return sqrt_n * sqrt_n == n

def mystery(x):
    # 1. Input type check: Must be a string.
    if not isinstance(x, str):
        return False

    # 2. Structure check: Must follow the pattern "P-N-H"
    #    - P (prefix): lowercase vowels ('a', 'e', 'i', 'o', 'u'), length 5 to 7.
    #    - N (number): sequence of digits, length 4 to 6.
    #    - H (hex_suffix): lowercase hexadecimal characters, length 10 to 14 (i.e., 5 to 7 bytes).
    match = re.fullmatch(r"([aeiou]{5,7})-([0-9]{4,6})-([0-9a-f]{10,14})", x)
    if not match:
        return False

    prefix, num_str, hex_suffix = match.groups()

    # 3. Prefix conditions:
    #    a. The sum of ASCII values of its characters must be a Fibonacci number.
    prefix_sum_ascii = sum(ord(c) for c in prefix)
    if not is_fibonacci(prefix_sum_ascii):
        return False
    #    b. The first character of the prefix must have a prime ASCII value.
    if not is_prime(ord(prefix[0])):
        return False

    # 4. Numeric part conditions:
    #    a. Convert num_str to an integer `N`.
    N = int(num_str)
    #    b. N must be a perfect square.
    if not is_perfect_square(N):
        return False
    #    c. The sum of the *unique* digits of N must be a prime number.
    sum_unique_digits_N = sum(int(d) for d in set(num_str))
    if not is_prime(sum_unique_digits_N):
        return False

    # 5. Hex Suffix conditions:
    #    a. Convert hex_suffix to bytes. This implicitly checks if hex_suffix is valid hex.
    try:
        suffix_bytes = bytes.fromhex(hex_suffix)
    except ValueError:
        return False

    #    b. The length of suffix_bytes must be a prime number.
    if not is_prime(len(suffix_bytes)):
        return False

    #    c. The CRC32 of suffix_bytes must have its low 8 bits equal to `N % 256`.
    crc_suffix = binascii.crc32(suffix_bytes) & 0xFFFFFFFF # Ensure 32-bit unsigned
    if (crc_suffix & 0xFF) != (N % 256):
        return False

    # 6. Cross-part condition (HMAC):
    #    The SHA256 HMAC of `suffix_bytes` using `prefix.encode()` as the key
    #    must have its last byte equal to the middle byte of `suffix_bytes`.
    hmac_key = prefix.encode('utf-8')
    hmac_msg = suffix_bytes
    hmac_tag_digest = hmac.new(hmac_key, hmac_msg, hashlib.sha256).digest()

    middle_suffix_byte = suffix_bytes[len(suffix_bytes) // 2]
    if hmac_tag_digest[-1] != middle_suffix_byte:
        return False

    # 7. Final overall hash condition:
    #    The SHA256 hash of the entire input `x` (UTF-8 encoded) must have
    #    its byte at index `(N % 20)` equal to its byte at index `(prefix_sum_ascii % 30)`.
    full_hash = hashlib.sha256(x.encode('utf-8')).digest()
    
    idx1 = N % 20
    idx2 = prefix_sum_ascii % 30
    
    # The hash is 32 bytes long, so indices 0-31 are always valid for N up to 999999 and prefix_sum_ascii up to 7*117 = 819.
    # N % 20 will be 0-19.
    # prefix_sum_ascii % 30 will be 0-29.
    # So, no need for explicit bounds check here.
    if full_hash[idx1] != full_hash[idx2]:
        return False

    return True
aaauia-1024-e2b36a6ab7
Proposer: gemini-2.5-flash Solver: gpt-5.2-2025-12-11
-4 vs -4
#9 Sample Solution Wrong
import hashlib
import hmac
import base64
import binascii
import re

def mystery(x):
    # Only strings are accepted.
    if not isinstance(x, str):
        return False

    # Format: p2.<b64url_payload>.<tag>
    m = re.fullmatch(r"p2\.([A-Za-z0-9_-]{6,64})\.([0-9a-f]{40})", x)
    if not m:
        return False

    payload_b64, tag_hex = m.group(1), m.group(2)

    # Base64url decode with required padding behavior (canonical-ish).
    pad = "=" * ((4 - (len(payload_b64) % 4)) % 4)
    try:
        payload = base64.urlsafe_b64decode(payload_b64 + pad)
    except Exception:
        return False

    # Payload must be ASCII printable and contain exactly one slash.
    if not payload or any(b < 0x20 or b > 0x7e for b in payload):
        return False
    if payload.count(b"/") != 1:
        return False

    left, right = payload.split(b"/", 1)

    # Left: 2..10 lowercase letters
    if not re.fullmatch(rb"[a-z]{2,10}", left):
        return False

    # Right: 1..8 decimal digits (no leading '+', etc.)
    if not re.fullmatch(rb"\d{1,8}", right):
        return False

    n = int(right)

    # Lightweight numeric gate tied to the payload bytes (CRC low 12 bits).
    crc = binascii.crc32(payload) & 0xffffffff
    if (crc & 0xFFF) != (n ^ len(left) ^ 0xA5B) & 0xFFF:
        return False

    # Key derivation depends on payload (hard to spoof without knowing target).
    key = hashlib.sha256(b"p2|key|" + left + b"|" + str(n).encode("ascii")).digest()

    # Tag is HMAC-SHA1 over a structured message.
    msg = b"p2|" + bytes([len(payload) ^ 0x3C]) + payload + b"|" + hashlib.sha256(payload).digest()[:8]
    tag = hmac.new(key, msg, hashlib.sha1).hexdigest()

    if tag != tag_hex:
        return False

    # Final hash relation gate (small, annoying constraint).
    h = hashlib.sha256(x.encode("utf-8")).digest()
    t = hashlib.sha256(b"anchor:" + left).digest()
    return (h[7] ^ h[19] ^ t[3]) == (n & 0xFF)
"p2.YWEvMA.16f30c4f5e0d8b2e9a5b7cbd6a0d6a8d0a51c9f5"
Proposer: gpt-5.2-2025-12-11 Solver: gemini-2.5-flash
-5 vs -4
#10 Sample Solution Wrong
import hashlib
import re
import math
import binascii
import hmac
import string

def is_prime(n):
    """Helper function to check if a number is prime."""
    if n < 2: return False
    for i in range(2, int(math.sqrt(n)) + 1):
        if n % i == 0: return False
    return True

def is_perfect_square(n):
    """Helper function to check if a number is a perfect square."""
    if n < 0: return False
    if n == 0: return True
    sqrt_n = int(math.sqrt(n))
    return sqrt_n * sqrt_n == n

def product_of_digits(n_str):
    """Helper function to calculate the product of digits in a string number."""
    prod = 1
    for digit_char in n_str:
        prod *= int(digit_char)
    return prod

def mystery(x):
    # 1. Input type check: Must be a string.
    if not isinstance(x, str):
        return False

    # 2. Structure check: Must follow the pattern "KW:<N>:<HS>"
    #    - KW (key_word_phrase): alphanumeric characters, length 6 to 10.
    #    - N (number): sequence of digits, length 3 to 7.
    #    - HS (hex_signature): lowercase hexadecimal characters, length 16 (i.e., 8 bytes).
    match = re.fullmatch(r"([a-zA-Z0-9]{6,10}):([0-9]{3,7}):([0-9a-f]{16})", x)
    if not match:
        return False

    kw, n_str, hs_hex = match.groups()

    # 3. Key Word Phrase (KW) conditions:
    #    a. KW must contain at least one uppercase letter.
    if not any(c.isupper() for c in kw):
        return False
    #    b. The sum of ASCII values of its characters must be a perfect square.
    kw_sum_ascii = sum(ord(c) for c in kw)
    if not is_perfect_square(kw_sum_ascii):
        return False

    # 4. Numeric part (N) conditions:
    #    a. Convert n_str to an integer N_val.
    N_val = int(n_str)
    #    b. N_val must be a prime number.
    if not is_prime(N_val):
        return False
    #    c. The product of its digits must be a perfect cube.
    prod_digits_N = product_of_digits(n_str)
    if prod_digits_N < 0: return False # Should not happen for digits, but defensive.
    cbrt_prod_digits = round(prod_digits_N**(1/3))
    if cbrt_prod_digits**3 != prod_digits_N:
        return False

    # 5. Hex Signature (HS) conditions:
    #    a. Convert hs_hex to bytes. This implicitly checks if hs_hex is valid hex.
    try:
        hs_bytes = bytes.fromhex(hs_hex)
    except ValueError:
        return False
    #    b. The hs_bytes must contain at least two identical bytes.
    if len(set(hs_bytes)) == len(hs_bytes): # All bytes are unique
        return False
    #    c. The CRC32 of hs_bytes must have its low 16 bits (bits 0-15)
    #       equal to N_val % 65536.
    crc_hs = binascii.crc32(hs_bytes) & 0xFFFFFFFF # Ensure 32-bit unsigned
    if (crc_hs & 0xFFFF) != (N_val % 65536):
        return False

    # 6. Cross-part condition (HMAC):
    #    The SHA256 HMAC of `kw.encode('utf-8')` using `str(N_val).encode('utf-8')` as the key
    #    must have its first byte equal to `(len(hs_bytes) + ord(kw[0])) % 256`.
    hmac_key = str(N_val).encode('utf-8')
    hmac_msg = kw.encode('utf-8')
    hmac_tag_digest = hmac.new(hmac_key, hmac_msg, hashlib.sha256).digest()

    target_hmac_first_byte = (len(hs_bytes) + ord(kw[0])) % 256
    if hmac_tag_digest[0] != target_hmac_first_byte:
        return False

    # 7. Final overall hash condition:
    #    The SHA256 hash of the entire input `x` (UTF-8 encoded) must have
    #    its last byte equal to `(len(kw) + N_val) % 256`.
    full_hash = hashlib.sha256(x.encode('utf-8')).digest()
    target_overall_hash_last_byte = (len(kw) + N_val) % 256
    if full_hash[-1] != target_overall_hash_last_byte:
        return False

    return True
Aqrqrqa:101:00000102030438a2
Proposer: gemini-2.5-flash Solver: gpt-5.2-2025-12-11
-5 vs -5