def mystery(x):
# Accepts either an integer-like number or a string that Python's int(..., 0) can parse.
if isinstance(x, bool):
return False
if isinstance(x, int):
n = x
elif isinstance(x, float):
# Only accept exact integers representable as floats (no inf/nan).
if not (x == x and x != float("inf") and x != float("-inf")):
return False
if int(x) != x:
return False
n = int(x)
elif isinstance(x, str):
s = x.strip().lower().replace("_", "")
try:
n = int(s, 0)
except Exception:
return False
else:
return False
# Keep the search space bounded (and make the constraints uniquely pin down n).
MOD1 = 1 << 17 # 131072
MOD2 = 3 ** 10 # 59049
MOD3 = 5 ** 8 # 390625
MAXN = MOD1 * MOD2 * MOD3 # 3023308800000000
if not (0 <= n < MAXN):
return False
# A small "key" from which the real targets are derived.
K = 0x1BFBB726780F83FD
u = ((K >> 0) & 0xFFFF) ^ 0xBEEF
v = ((K >> 16) & 0xFFFF) ^ 0xCAFE
w = (((K >> 32) ^ 0x00FACE00) & 0xFFFFFF)
ds_target = ((K >> 56) & 0xFF) ^ 0x5A
# Targets (not stored directly).
r1 = (u ^ 0x13579) & (MOD1 - 1)
r2 = (v * 17 + u) % MOD2
r3 = (w * 313 + v) % MOD3
if (n % MOD1) != r1:
return False
if (n % MOD2) != r2:
return False
if (n % MOD3) != r3:
return False
# Extra constraint: sum of decimal digits must match a hidden target.
t = n
s = 0
while t:
t, d = divmod(t, 10)
s += d
if s != ds_target:
return False
return True
import unicodedata
def mystery(x):
"""
Accepts either a string or a number (integers only). Returns True for a very small
hidden set of strings/numbers that satisfy several nontrivial numeric and Unicode
checks. The intent is to make reverse-engineering which values pass difficult.
"""
# Reject booleans explicitly
if isinstance(x, bool):
return False
# Normalize input to a string for the checks
if isinstance(x, int):
s = str(x)
elif isinstance(x, float):
# only accept exact integers encoded as float
if not (x == x and x != float("inf") and x != float("-inf")):
return False
if int(x) != x:
return False
s = str(int(x))
elif isinstance(x, str):
s = x
else:
return False
# Unicode normalization and simple canonicalization
s = unicodedata.normalize("NFC", s).strip().lower()
# Basic guards to keep search space small-ish
if any(ch.isspace() for ch in s):
return False
if not (1 <= len(s) <= 40):
return False
# Constraint A: exact length (narrows the space)
if len(s) != 9:
return False
# Constraint B: sum of codepoints mod 97 must match hidden target
cps = [ord(ch) for ch in s]
sum_cp = sum(cps)
if (sum_cp % 97) != 6:
return False
# Constraint C: quadratic checksum mod 1_000_003
sum_sq = sum(c * c for c in cps)
qc = (13 * sum_cp + 7 * sum_sq) % 1_000_003
if qc != 72217:
return False
# Constraint D: rolling polynomial hash (base 131, mod 1_000_000_007)
MOD = 1_000_000_007
h = 0
for c in cps:
h = (h * 131 + c) % MOD
if h != 158198523:
return False
# All checks passed
return True
import unicodedata
import hashlib
import hmac
def mystery(x):
# Reject booleans explicitly (since bool is a subclass of int).
if isinstance(x, bool):
return False
# Coerce input to a string in a few allowed ways.
if isinstance(x, int):
s = str(x)
elif isinstance(x, float):
# Accept only exact integers representable as finite floats.
if not (x == x and x not in (float("inf"), float("-inf"))):
return False
if int(x) != x:
return False
s = str(int(x))
elif isinstance(x, str):
s = x
else:
return False
# Canonicalize.
s = unicodedata.normalize("NFKC", s).strip()
# Guardrails: keep it "string-like" and small.
if not (1 <= len(s) <= 32):
return False
if any(ch.isspace() for ch in s):
return False
if any(ord(ch) < 0x20 or ord(ch) > 0x7E for ch in s):
return False
b = s.encode("utf-8")
if len(b) != 11:
return False
def ror8(v, r):
r &= 7
return ((v >> r) | ((v << (8 - r)) & 0xFF)) & 0xFF
# Hidden expected bytes are derived indirectly.
stored = (0x97, 0x31, 0x71, 0x52, 0xC3, 0x34, 0x5F, 0x0D, 0x34, 0xBB, 0x92)
exp = bytearray()
for i, sb in enumerate(stored):
mask = (((73 * i + 19) & 0xFF) ^ 0x5A) & 0xFF
c = sb ^ mask
u = ror8(c, 3)
t = (u - 17) & 0xFF
p = t ^ 0xA5
exp.append(p)
exp = bytes(exp)
# Extra checks (redundant but adds noise): a keyed digest equality.
key = hashlib.sha256(exp + b"\x00\xff" + exp[::-1]).digest()[:16]
if not hmac.compare_digest(
hashlib.blake2s(b, key=key, digest_size=20).digest(),
hashlib.blake2s(exp, key=key, digest_size=20).digest(),
):
return False
# Final exact match.
return hmac.compare_digest(b, exp)
import unicodedata
import hashlib
import hmac
def mystery(x):
"""
Accepts an int/float/string and returns True iff the canonicalized UTF-8 bytes
of the input exactly match a hidden 9-byte target. Several guards are present
to keep inputs "sane" (no whitespace, printable ASCII, NFC normalization, etc.)
and to add noise (a keyed digest equality) so the final equality isn't the only
check you see at a glance.
"""
# Reject booleans explicitly (bool is a subclass of int).
if isinstance(x, bool):
return False
# Coerce input to a string in a few allowed ways.
if isinstance(x, int):
s = str(x)
elif isinstance(x, float):
# Accept only finite exact integers encoded as float.
if not (x == x and x not in (float("inf"), float("-inf"))):
return False
if int(x) != x:
return False
s = str(int(x))
elif isinstance(x, str):
s = x
else:
return False
# Canonicalize
s = unicodedata.normalize("NFC", s).strip()
# Basic guards
if not (1 <= len(s) <= 32):
return False
if any(ch.isspace() for ch in s):
return False
# Only allow printable ASCII for this puzzle
if any(ord(ch) < 33 or ord(ch) > 126 for ch in s):
return False
b = s.encode("utf-8")
# The hidden target is exactly 9 bytes long.
if len(b) != 9:
return False
# Construct the hidden target in an obfuscated way (but deterministically).
# These small arithmetic forms hide the obvious ASCII but are easy to verify.
target = bytes([
(0x70 + 2), # 114 -> 'r'
(0x60 + 1), # 97 -> 'a'
(0x70 + 6), # 118 -> 'v'
(0x60 + 5), # 101 -> 'e'
(0x60 + 14), # 110 -> 'n'
(0x60 + 3), # 99 -> 'c'
(0x60 + 12), # 108 -> 'l'
(0x60 + 1), # 97 -> 'a'
(0x70 + 7), # 119 -> 'w'
])
# An additional keyed check (noise): must match keyed Blake2s digest derived from target.
key = hashlib.sha256(target + b"\x13\x37" + target[::-1]).digest()[:16]
if not hmac.compare_digest(
hashlib.blake2s(b, key=key, digest_size=20).digest(),
hashlib.blake2s(target, key=key, digest_size=20).digest(),
):
return False
# Final exact match required.
return hmac.compare_digest(b, target)
import unicodedata
import hashlib
import hmac
def mystery(x):
# Reject bool explicitly (bool is a subclass of int).
if isinstance(x, bool):
return False
# Coerce to string in allowed ways.
if isinstance(x, int):
s = str(x)
elif isinstance(x, float):
# Only accept finite floats that are exact integers.
if not (x == x and x not in (float("inf"), float("-inf"))):
return False
if int(x) != x:
return False
s = str(int(x))
elif isinstance(x, str):
s = x
else:
return False
# Canonicalize.
s = unicodedata.normalize("NFKC", s).strip()
# Guardrails.
if any(ch.isspace() for ch in s):
return False
if len(s) != 16:
return False
if any(ord(ch) < 33 or ord(ch) > 126 for ch in s):
return False
b = s.encode("utf-8")
if len(b) != 16:
return False
def rol8(v, r):
r &= 7
return ((v << r) & 0xFF) | (v >> (8 - r))
# Reconstruct the 16-byte target (obfuscated as two XOR-masked 64-bit chunks).
c1 = 0xACBA995621339A6F
c2 = 0xE695C056AB0ACA1A
m1 = 0x0123456789ABCDEF
m2 = 0x0FEDCBA987654321
hi = c1 ^ m1
lo = c2 ^ m2
target = hi.to_bytes(8, "big") + lo.to_bytes(8, "big")
# Reversible byte-scramble of the candidate; must match target.
out = bytearray(16)
for i in range(16):
add = (17 * i + 23) & 0xFF
r = (3 * i + 1) & 7
mask = (0xA5 ^ ((29 * i + 7) & 0xFF)) & 0xFF
v = (b[i] + add) & 0xFF
v = rol8(v, r)
v ^= mask
out[i] = v
out = bytes(out)
# Extra "noise" check: keyed digest equality (effectively enforces out == target).
key = hashlib.sha256(target + b"\x00\xff" + target[::-1]).digest()[:16]
if not hmac.compare_digest(
hashlib.blake2s(out, key=key, digest_size=20).digest(),
hashlib.blake2s(target, key=key, digest_size=20).digest(),
):
return False
# Final check.
return hmac.compare_digest(out, target)
import unicodedata
import hashlib
import hmac
def mystery(x):
# Reject booleans explicitly
if isinstance(x, bool):
return False
# Accept int/float (exact integer) or str
if isinstance(x, int):
s = str(x)
elif isinstance(x, float):
if not (x == x and x not in (float("inf"), float("-inf"))):
return False
if int(x) != x:
return False
s = str(int(x))
elif isinstance(x, str):
s = x
else:
return False
# Canonicalize and basic guards
s = unicodedata.normalize("NFKC", s).strip()
if any(ch.isspace() for ch in s):
return False
if not (1 <= len(s) <= 24):
return False
# only printable ASCII
if any(ord(ch) < 33 or ord(ch) > 126 for ch in s):
return False
# The hidden target is 12 bytes long
if len(s) != 12:
return False
b = s.encode("utf-8")
if len(b) != 12:
return False
def rol8(v, r):
r &= 7
return ((v << r) & 0xFF) | (v >> (8 - r))
def ror8(v, r):
r &= 7
return (v >> r) | ((v << (8 - r)) & 0xFF)
# Obfuscated stored values derived from the true target bytes.
stored = (
248, 186, 21, 54, 218, 166, 68, 251, 20, 239, 6, 125
)
# Reconstruct the expected bytes by reversing the obfuscation.
exp = bytearray()
for i, sb in enumerate(stored):
add = (31 * i + 7) & 0xFF
r = (5 * i + 3) & 7
mask = (0x9F ^ ((17 * i + 13) & 0xFF)) & 0xFF
u = (sb + add) & 0xFF
t = ror8(u, r)
v = t ^ mask
exp.append(v)
exp = bytes(exp)
# Noise: keyed digest must match (forces candidate bytes to equal reconstructed bytes).
key = hashlib.sha256(exp + b"\x42\x24" + exp[::-1]).digest()[:16]
if not hmac.compare_digest(
hashlib.blake2s(b, key=key, digest_size=20).digest(),
hashlib.blake2s(exp, key=key, digest_size=20).digest(),
):
return False
# Final exact match
return hmac.compare_digest(b, exp)
import unicodedata
import hashlib
import hmac
import zlib
def mystery(x):
# Reject bool explicitly (bool is a subclass of int)
if isinstance(x, bool):
return False
# Coerce input to a string (numbers are accepted but will not satisfy the later ASCII/length checks here)
if isinstance(x, int):
s = str(x)
elif isinstance(x, float):
# accept only finite exact integers as floats
if not (x == x and x not in (float("inf"), float("-inf"))):
return False
if int(x) != x:
return False
s = str(int(x))
elif isinstance(x, str):
s = x
else:
return False
# Canonicalize (keeps behavior deterministic for Unicode lookalikes)
s = unicodedata.normalize("NFKC", s).strip()
# Guardrails
if any(ch.isspace() for ch in s):
return False
if len(s) != 24:
return False
if any(ord(ch) < 33 or ord(ch) > 126 for ch in s):
return False
b = s.encode("utf-8")
if len(b) != 24:
return False
def rol8(v, r):
r &= 7
return ((v << r) & 0xFF) | (v >> (8 - r))
def ror8(v, r):
r &= 7
return (v >> r) | ((v << (8 - r)) & 0xFF)
# Stored bytes are NOT the answer; they are the result of a position-dependent reversible transform.
stored = (
158, 231, 246, 64, 214, 4, 102, 166,
148, 9, 71, 78, 144, 110, 193, 0,
101, 114, 116, 32, 140, 93, 145, 46
)
# Reconstruct the expected 24 bytes by inverting the transform.
exp = bytearray(24)
for i, sb in enumerate(stored):
mask = (0xA7 + 13 * i) & 0xFF
r = (5 * i + 1) & 7
add = (17 * i + 29) & 0xFF
v = (sb - add) & 0xFF
v = ror8(v, r)
v ^= mask
exp[i] = v
exp = bytes(exp)
# Extra "noise" checks that depend on exp but don't reveal it directly.
# (1) CRC on a transformed view of the candidate must match the expected one.
twist = bytes(rol8(bb ^ ((i * 31 + 7) & 0xFF), i) for i, bb in enumerate(b))
exp_twist = bytes(rol8(eb ^ ((i * 31 + 7) & 0xFF), i) for i, eb in enumerate(exp))
if zlib.crc32(twist) != zlib.crc32(exp_twist):
return False
# (2) Keyed digest equality (effectively enforces b == exp).
kseed = bytes((p ^ q) for p, q in zip(exp, exp[::-1])) + b"\x01\x7f"
key = hashlib.sha256(kseed).digest()[:16]
if not hmac.compare_digest(
hashlib.blake2s(b, key=key, digest_size=20).digest(),
hashlib.blake2s(exp, key=key, digest_size=20).digest(),
):
return False
# Final exact match.
return hmac.compare_digest(b, exp)
import unicodedata
import hashlib
import hmac
import zlib
def mystery(x):
# Reject booleans (bool is a subclass of int in Python).
if isinstance(x, bool):
return False
# Coerce to string in allowed ways.
if isinstance(x, int):
s = str(x)
elif isinstance(x, float):
# only accept finite exact integers encoded as float
if not (x == x and x not in (float("inf"), float("-inf"))):
return False
if int(x) != x:
return False
s = str(int(x))
elif isinstance(x, str):
s = x
else:
return False
# Canonicalize
s = unicodedata.normalize("NFKC", s).strip()
# Basic guards: printable ASCII, no whitespace, exact length 13
if any(ch.isspace() for ch in s):
return False
if len(s) != 13:
return False
if any(ord(ch) < 33 or ord(ch) > 126 for ch in s):
return False
b = s.encode("utf-8")
if len(b) != 13:
return False
def rol8(v, r):
r &= 7
return ((v << r) & 0xFF) | (v >> (8 - r))
def ror8(v, r):
r &= 7
return (v >> r) | ((v << (8 - r)) & 0xFF)
# These stored bytes are the obfuscated form of the true 13-byte target.
stored = (
53, 9, 252, 107, 82, 145, 176, 244, 58, 140, 99, 217, 145
)
# Reconstruct expected bytes by inverting the obfuscation.
exp = bytearray()
for i, sb in enumerate(stored):
mask = (0xA5 ^ ((17 * i + 13) & 0xFF)) & 0xFF
r = (5 * i + 3) & 7
add = (31 * i + 7) & 0xFF
v = (sb - add) & 0xFF
t = ror8(v, r)
byte = t ^ mask
exp.append(byte)
exp = bytes(exp)
# Noise check: CRC of a twisted view must match (depends on exp)
twist = bytes(rol8(bb ^ ((i * 47 + 19) & 0xFF), (3 * i + 1)) for i, bb in enumerate(b))
exp_twist = bytes(rol8(eb ^ ((i * 47 + 19) & 0xFF), (3 * i + 1)) for i, eb in enumerate(exp))
if zlib.crc32(twist) != zlib.crc32(exp_twist):
return False
# Keyed digest equality (noise that enforces candidate == exp)
key = hashlib.sha256(exp + b"\x13\x37" + exp[::-1]).digest()[:16]
if not hmac.compare_digest(
hashlib.blake2s(b, key=key, digest_size=20).digest(),
hashlib.blake2s(exp, key=key, digest_size=20).digest(),
):
return False
# Final exact match
return hmac.compare_digest(b, exp)
import unicodedata
import hashlib
import hmac
import zlib
def mystery(x):
# --- input handling ---
if isinstance(x, bool):
return False
if isinstance(x, int):
s = str(x)
elif isinstance(x, float):
if not (x == x and x not in (float("inf"), float("-inf"))):
return False
if int(x) != x:
return False
s = str(int(x))
elif isinstance(x, str):
s = x
else:
return False
s = unicodedata.normalize("NFKC", s).strip()
if any(ch.isspace() for ch in s):
return False
if len(s) != 18:
return False
if any(ord(ch) < 33 or ord(ch) > 126 for ch in s):
return False
try:
b = s.encode("ascii")
except Exception:
return False
if len(b) != 18:
return False
# --- byte machinery ---
def rol8(v, r):
r &= 7
return ((v << r) & 0xFF) | ((v & 0xFF) >> (8 - r))
def mix(data, seed):
st = seed & 0xFFFFFFFF
out = bytearray(len(data))
for i, bb in enumerate(data):
k0 = (st >> ((i & 3) * 8)) & 0xFF
k1 = (st >> 8) & 0xFF
k2 = (st >> 24) & 0xFF
v = bb ^ k0
v = rol8(v, (3 * i + 5) & 7)
v = (v + k1 + (17 * i + 11)) & 0xFF
ob = v ^ k2
out[i] = ob
# Update state with a non-cryptographic avalanche step (obfuscation/noise).
st ^= (ob & 0xFF) << ((i & 3) * 8)
st = (st * 0x045D9F3B + 0x1337 + i) & 0xFFFFFFFF
st ^= (st >> 16)
return bytes(out), st
# Hidden target bytes (encoded as a big-endian integer, not a visible string).
# (18 bytes => 144 bits)
PINT = int("633064335f70757a7a6c332d323032362121", 16)
p = PINT.to_bytes(18, "big")
exp, st_exp = mix(p, 0xC0FFEE42)
got, st_got = mix(b, 0xC0FFEE42)
# --- redundant constraints (noise) ---
# Two different invariants that must match the expected candidate.
twist_got = bytes(rol8(bb ^ ((i * 29 + 7) & 0xFF), i) for i, bb in enumerate(got))
twist_exp = bytes(rol8(eb ^ ((i * 29 + 7) & 0xFF), i) for i, eb in enumerate(exp))
if zlib.crc32(twist_got) != zlib.crc32(twist_exp):
return False
if st_got != st_exp:
return False
key = hashlib.sha256(exp + b"\x00\xff" + exp[::-1]).digest()[:16]
if not hmac.compare_digest(
hashlib.blake2s(got, key=key, digest_size=20).digest(),
hashlib.blake2s(exp, key=key, digest_size=20).digest(),
):
return False
return hmac.compare_digest(got, exp)
import unicodedata
import hashlib
import hmac
import zlib
def mystery(x):
"""
Accepts an int/float/string and returns True only for one very small hidden string.
The function canonicalizes the input, enforces printable-ASCII/no-whitespace/length
constraints, reconstructs a hidden 11-byte target from an obfuscated stored tuple,
runs a couple of noisy invariants, and finally requires an exact bytewise match.
"""
# Reject booleans explicitly (bool is a subclass of int).
if isinstance(x, bool):
return False
# Coerce input to string in a few allowed ways.
if isinstance(x, int):
s = str(x)
elif isinstance(x, float):
# only accept finite exact integers encoded as float
if not (x == x and x not in (float("inf"), float("-inf"))):
return False
if int(x) != x:
return False
s = str(int(x))
elif isinstance(x, str):
s = x
else:
return False
# Canonicalize
s = unicodedata.normalize("NFKC", s).strip()
# Basic guards
if any(ch.isspace() for ch in s):
return False
if len(s) != 11:
return False
if any(ord(ch) < 33 or ord(ch) > 126 for ch in s):
return False
b = s.encode("utf-8")
if len(b) != 11:
return False
def rol8(v, r):
r &= 7
return ((v << r) & 0xFF) | (v >> (8 - r))
def ror8(v, r):
r &= 7
return (v >> r) | ((v << (8 - r)) & 0xFF)
# Obfuscated stored bytes (not the direct target).
stored = (
72, 231, 203, 94, 112, 202, 13, 145, 73, 202, 124
)
# Reconstruct the expected bytes by inverting the obfuscation applied to the stored tuple.
exp = bytearray()
for i, sb in enumerate(stored):
mask = (0xAA ^ ((17 * i + 13) & 0xFF)) & 0xFF
r = (3 * i + 5) & 7
add = (31 * i + 7) & 0xFF
kb = (0x37 + 11 * i) & 0xFF
v = sb ^ mask
v = (v - add) & 0xFF
t = ror8(v, r)
byte = t ^ kb
exp.append(byte)
exp = bytes(exp)
# Noise check 1: twisted CRC must match (depends on exp but doesn't reveal it directly).
twist = bytes(rol8(bb ^ ((i * 47 + 19) & 0xFF), (i + 3) & 7) for i, bb in enumerate(b))
exp_twist = bytes(rol8(eb ^ ((i * 47 + 19) & 0xFF), (i + 3) & 7) for i, eb in enumerate(exp))
if zlib.crc32(twist) != zlib.crc32(exp_twist):
return False
# Noise check 2: keyed digest equality enforces candidate == exp (with obfuscation).
key = hashlib.sha256(exp + b"\x13\x37" + exp[::-1]).digest()[:16]
if not hmac.compare_digest(
hashlib.blake2s(b, key=key, digest_size=20).digest(),
hashlib.blake2s(exp, key=key, digest_size=20).digest(),
):
return False
# Final exact match.
return hmac.compare_digest(b, exp)