{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Welcome to the Second Lab - Week 1, Day 3\n", "\n", "Today we will work with lots of models! This is a way to get comfortable with APIs." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", " \n", " \n", " \n", " \n", "
\n", " \n", " \n", "

Important point - please read

\n", " The way I collaborate with you may be different to other courses you've taken. I prefer not to type code while you watch. Rather, I execute Jupyter Labs, like this, and give you an intuition for what's going on. My suggestion is that you carefully execute this yourself, after watching the lecture. Add print statements to understand what's going on, and then come up with your own variations.

If you have time, I'd love it if you submit a PR for changes in the community_contributions folder - instructions in the resources. Also, if you have a Github account, use this to showcase your variations. Not only is this essential practice, but it demonstrates your skills to others, including perhaps future clients or employers...\n", "
\n", "
" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "# Start with imports - ask ChatGPT to explain any package that you don't know\n", "\n", "import os\n", "import json\n", "from dotenv import load_dotenv\n", "from openai import OpenAI\n", "from anthropic import Anthropic\n", "from IPython.display import Markdown, display" ] }, { "cell_type": "code", "execution_count": 35, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 35, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Always remember to do this!\n", "load_dotenv(override=True)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "OpenAI API Key exists and begins sk-proj-\n", "Anthropic API Key exists and begins sk-ant-\n", "Google API Key exists and begins AQ\n", "DeepSeek API Key not set (and this is optional)\n", "Groq API Key not set (and this is optional)\n" ] } ], "source": [ "# Print the key prefixes to help with any debugging\n", "\n", "openai_api_key = os.getenv('OPENAI_API_KEY')\n", "anthropic_api_key = os.getenv('ANTHROPIC_API_KEY')\n", "google_api_key = os.getenv('GOOGLE_API_KEY')\n", "deepseek_api_key = os.getenv('DEEPSEEK_API_KEY')\n", "groq_api_key = os.getenv('GROQ_API_KEY')\n", "\n", "if openai_api_key:\n", " print(f\"OpenAI API Key exists and begins {openai_api_key[:8]}\")\n", "else:\n", " print(\"OpenAI API Key not set\")\n", " \n", "if anthropic_api_key:\n", " print(f\"Anthropic API Key exists and begins {anthropic_api_key[:7]}\")\n", "else:\n", " print(\"Anthropic API Key not set (and this is optional)\")\n", "\n", "if google_api_key:\n", " print(f\"Google API Key exists and begins {google_api_key[:2]}\")\n", "else:\n", " print(\"Google API Key not set (and this is optional)\")\n", "\n", "if deepseek_api_key:\n", " print(f\"DeepSeek API Key exists and begins {deepseek_api_key[:3]}\")\n", "else:\n", " print(\"DeepSeek API Key not set (and this is optional)\")\n", "\n", "if groq_api_key:\n", " print(f\"Groq API Key exists and begins {groq_api_key[:4]}\")\n", "else:\n", " print(\"Groq API Key not set (and this is optional)\")" ] }, { "cell_type": "code", "execution_count": 44, "metadata": {}, "outputs": [], "source": [ "request = \"Please come up with a challenging, nuanced question that I can ask a number of LLMs to evaluate their intelligence. \"\n", "request += \"Answer only with the question, no explanation.\"\n", "messages = [{\"role\": \"user\", \"content\": request}]" ] }, { "cell_type": "code", "execution_count": 45, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[{'role': 'user',\n", " 'content': 'Please come up with a challenging, nuanced question that I can ask a number of LLMs to evaluate their intelligence. Answer only with the question, no explanation.'}]" ] }, "execution_count": 45, "metadata": {}, "output_type": "execute_result" } ], "source": [ "messages" ] }, { "cell_type": "code", "execution_count": 46, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "You are given a sealed black box that implements a function \\(f:\\{0,1\\}^{128}\\to\\{0,1\\}^{128}\\). You may submit up to 2,000 adaptively chosen 128-bit inputs and observe the outputs. You are told that \\(f\\) is exactly one of the following:\n", "\n", "1. A uniformly random permutation on 128-bit strings.\n", "2. AES-128 with an unknown key, applied in ECB mode to each 128-bit block independently.\n", "3. \\(f(x)=A x \\oplus b\\), where \\(A\\) is an unknown invertible \\(128\\times128\\) binary matrix and \\(b\\) is an unknown 128-bit vector.\n", "4. \\(f(x)=g(x)\\,\\|\\,h(x)\\), where \\(g\\) outputs the first 64 bits and is a random permutation on 64-bit strings, while \\(h\\) outputs the last 64 bits and is an independent random permutation on 64-bit strings.\n", "5. \\(f(x)=x\\oplus K\\) for a fixed unknown 128-bit key \\(K\\).\n", "\n", "You are not allowed to use any computational resources beyond paper reasoning, and you do not know the source or training data of the box.\n", "\n", "Your task is to design, in detail, an adaptive querying strategy that, with the highest possible success probability, identifies which of the five cases holds. You must do all of the following:\n", "\n", "- State the minimum number of queries you believe is sufficient, or argue why no bounded number suffices.\n", "- For each query, specify exactly how it is chosen based on prior answers.\n", "- Give the decision rule for each possible transcript.\n", "- Justify why your strategy distinguishes cases 1–5 better than random guessing, including any information-theoretic or structural arguments.\n", "- If you believe two or more cases are information-theoretically indistinguishable under the query budget, explain precisely why and how you would modify the problem to make it distinguishable.\n" ] } ], "source": [ "openai = OpenAI()\n", "response = openai.chat.completions.create(\n", " model=\"gpt-5.4-mini\",\n", " messages=messages,\n", ")\n", "question = response.choices[0].message.content\n", "print(question)\n" ] }, { "cell_type": "code", "execution_count": 47, "metadata": {}, "outputs": [], "source": [ "competitors = []\n", "answers = []\n", "messages = [{\"role\": \"user\", \"content\": question}]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Note - update since the videos\n", "\n", "I've updated the model names to use the latest models below, like GPT 5 and Claude Sonnet 4.5. It's worth noting that these models can be quite slow - like 1-2 minutes - but they do a great job! Feel free to switch them for faster models if you'd prefer, like the ones I use in the video." ] }, { "cell_type": "code", "execution_count": 48, "metadata": {}, "outputs": [ { "data": { "text/markdown": [ "Below is a concrete, adaptive strategy that (i) uses a bounded number of 128‑bit queries, (ii) works for all five possibilities with high probability, and (iii) makes explicit the transcript-based decision rules. I also include a careful discussion of what can and cannot be guaranteed with the given budget, and how you could modify the problem if you want a provable distinction in all five cases.\n", "\n", "High-level plan (what we try to separate and why)\n", "\n", "- A quick affine/linear test lets us separate the “affine” family f(x) = A x ⊕ b from all the genuinely non‑affine possibilities (cases 1, 2, 4). This immediately distinguishes 5 (A = I, b = K) from all non‑affine cases with very high probability, and separates 3 (A arbitrary invertible) from 5.\n", "\n", "- If we flag affine and the test is consistent with A = I (the XOR-with-a-constant family), we can separate case 5 from the rest of the affine family using a small extra test (involution style): for case 5, f∘f = id; for generic affine (case 3 with A ≠ I), f∘f is not the identity for almost all inputs (and we can detect this with a couple of probes). This gives a robust way to distinguish 5 from 3, while still keeping error probability negligible.\n", "\n", "- If we flag non-affine (i.e., not in affine form), we can separate case 4 from cases 1 and 2 using a simple “factorization by halves” observation: in case 4, the first output half depends only on the first input half, and the second output half depends only on the second input half (g and h are independent 64‑bit permutations). In contrast, a random 128‑bit permutation (case 1) and AES in ECB (case 2) do not factorize this way. With a single carefully chosen pair of queries having the same first input half but different second halves, the first output half should be identical for 4 but not for 1 or 2 with overwhelming probability (2^-64 type small error). This lets us separate 4 from {1,2} with high confidence.\n", "\n", "- Distinguishing 1 vs 2 (uniform random permutation vs AES with an unknown key) cannot be guaranteed to succeed with a bounded, small query budget under standard cryptographic indistinguishability assumptions; both look like random permutations on the 128‑bit domain to any polynomially bounded test. I flag this explicitly and explain how you could modify the task if you want a provable separation in all five cases.\n", "\n", "Now the detailed strategy\n", "\n", "1) Meet-the-affine test (to pull case 3, 5 apart from 1, 2, 4)\n", "\n", "- Query preparation (6 inputs use, two independent triple tests to check affine structure):\n", " - Let X1 = 0^128 (all zero 128 bits).\n", " - Let X2 = 0^64 || 1^64 (first 64 bits zero, last 64 bits all ones).\n", " - Let X3 = X1 ⊕ X2 = 0^64 || 1^64 (note X3 ≠ X1, X3 ≠ X2).\n", "\n", " - Let X4 = 0^64 || 1^64 (the same as X2 for convenience; we’ll avoid accidental dependence by the second triple using a different base).\n", " - Let X5 = 1^64 || 0^64 (first half all ones, second half all zeros).\n", " - Let X6 = X4 ⊕ X5 = (1^64 || 1^64).\n", "\n", " The two triples are (X1, X2, X3) and (X4, X5, X6). They give two independent checks of the same affine-structure quantity.\n", "\n", "- For a generic affine function f(x) = A x ⊕ b over GF(2)^128, we have for any x,y:\n", " f(x) ⊕ f(y) ⊕ f(x ⊕ y) = b.\n", " Therefore, if f is affine, the 128‑bit value\n", " T(x,y) = f(x) ⊕ f(y) ⊕ f(x ⊕ y)\n", " is constant and equal to b, for all x,y. So for the two triples, we should observe\n", " t1 = f(X1) ⊕ f(X2) ⊕ f(X3) = b,\n", " t2 = f(X4) ⊕ f(X5) ⊕ f(X6) = b,\n", " hence t1 = t2 with extremely high probability (the only way they could differ is a ceil(2^-128)‑level collision across two independent evaluations).\n", "\n", "- What you actually do (queries and transcript):\n", " - Query 1: input X1 = 0^128; observe Y1 = f(X1).\n", " - Query 2: input X2 = 0^64 || 1^64; observe Y2 = f(X2).\n", " - Query 3: input X3 = X1 ⊕ X2; observe Y3 = f(X3).\n", " - Compute t1 = Y1 ⊕ Y2 ⊕ Y3.\n", "\n", " - Query 4: input X4 = 0^64 || 1^64; observe Y4 = f(X4).\n", " - Query 5: input X5 = 1^64 || 0^64; observe Y5 = f(X5).\n", " - Query 6: input X6 = X4 ⊕ X5; observe Y6 = f(X6).\n", " - Compute t2 = Y4 ⊕ Y5 ⊕ Y6.\n", "\n", "- Decision rule after 6 queries:\n", " - If t1 = t2 (down to exact bit equality, within machine precision), classify as affine (candidate 3 or 5).\n", " - If t1 ≠ t2, classify as non-affine (candidate 1, 2, or 4).\n", "\n", "Notes:\n", "- The probability that a non-affine function yields t1 = t2 for both triples is at most about 2^-128, so this yields a clean separation in practice.\n", "- If you want a safer margin, you can repeat the test with another independent pair of triples (costing a few more queries) and require two out of three to agree; with 2000 total budget this is still cheap and provides overwhelming confidence.\n", "\n", "2) If affine: separate 5 from 3 (robustly)\n", "\n", "- We are in the affine branch (t1 = t2). Now determine if A = I (i.e., f(x) = x ⊕ b) or not (i.e., f is a nontrivial affine map).\n", "- A simple, robust check is to test whether f∘f is the identity on a small, random subset of inputs. For f(x) = A x ⊕ b, one has\n", " f(f(x)) = A(Ax ⊕ b) ⊕ b = A^2 x ⊕ A b ⊕ b.\n", " In general, unless A^2 = I and A b = b, this will not equal x for most x.\n", "\n", "- Practical two-input involution tests (two queries suffice per test):\n", " - Test 1: Query x = 0^128, get y = f(x). Query z = f(y) and compare z with x.\n", " - For case 5 (A = I, f(x) = x ⊕ b with b ≡ K), f(f(0)) = 0, so z = 0 = x.\n", " - For most affine cases with A ≠ I, f(f(0)) ≠ 0.\n", " - Test 2: If Test 1 passed (z = x), test with another input x' = 1^128 (or any nonzero x) in the same way:\n", " - Compute y' = f(x'), z' = f(y'), check whether z' = x'.\n", " - Decision after two tests:\n", " - If both tests produce f(f(x)) = x for the two chosen x’s, declare 5.\n", " - If any test yields f(f(x)) ≠ x for some chosen x, declare 3.\n", "\n", "Notes and robustness:\n", "- It is possible in principle (though with small probability) that some affine maps with A ≠ I and a particular b satisfy f∘f = id for a few special x; to guard against that, you can choose two distinct nonzero inputs (as above) and require both pass; the probability that both pass for A ≠ I is still negligible in GF(2)^128.\n", "- If you want even stronger confidence you could test a third input as well, but two such tests already give overwhelming confidence that A ≠ I is unlikely and that you truly have 5 when all tests pass.\n", "\n", "3) If non-affine: separate 4 from {1, 2}\n", "\n", "- Now we are in the non-affine branch (cases 1, 2, 4). Use the “factorization by halves” property to pull out 4.\n", "\n", "- Choose a fixed first-half value a ∈ {0,1}^64 and two distinct second-half values b1 ≠ b2 ∈ {0,1}^64.\n", " - Query X = (a, b1) and Y = (a, b2). Observe F(X) and F(Y), each 128 bits.\n", "\n", "- Compare the first 64 bits of F(X) and F(Y).\n", "\n", "- Decision rule:\n", " - If the first halves of F(X) and F(Y) are identical, declare 4 with high confidence (the first output half in case 4 depends only on the first input half a; varying the second half b does not affect the first output half). The probability that the first halves match by accident for a random 128‑bit permutation (cases 1 or 2) is 2^-64, which is negligible. \n", " - If the first halves are different, declare not-4; the remaining possibilities are 1 or 2.\n", "\n", "- Distinguishing 1 vs 2 after ruling out 4:\n", " - This is the tricky part. With only 2000 queries, there is no known information-theoretic guarantee (under standard cryptographic assumptions) that you can distinguish a truly random 128‑bit permutation from AES-128 with an unknown key, because AES is designed to be a pseudorandom permutation indistinguishable from a random permutation with polynomially many queries. Hence, there is no bounded-number, deterministic strategy that, in the worst case, distinguishes 1 from 2 with non-negligible advantage. In practice, any such attempt relies on cryptanalytic assumptions rather than unconditional reasoning.\n", "\n", "- Practical stance for this subproblem:\n", " - If one accepts the standard cryptographic heuristic that AES with an unknown key is indistinguishable from a random permutation for polynomially many queries, then after you have eliminated 4, you should treat the remaining options as essentially indistinguishable within the given query budget. Your best operational choice then is to guess between 1 and 2 (e.g., random guess, or a fixed guess), accepting an impossibility to guarantee correctness better than random guessing. The failure probability would be roughly 1/2 for this last step, as long as you have not observed any distinguishing signature.\n", " - If you are allowed to modify the problem (see below), you could make this final distinction provable.\n", "\n", "Summary of the adaptive query plan and transcript rules\n", "\n", "- Total queries used for the affine test (Stage A): 6 queries\n", " - Q1: X1 = 0^128\n", " - Q2: X2 = 0^64 || 1^64\n", " - Q3: X3 = X1 ⊕ X2\n", " - Q4: X4 = 0^64 || 1^64\n", " - Q5: X5 = 1^64 || 0^64\n", " - Q6: X6 = X4 ⊕ X5\n", " - Transcript check: t1 = f(X1) ⊕ f(X2) ⊕ f(X3); t2 = f(X4) ⊕ f(X5) ⊕ f(X6).\n", " - If t1 = t2 → affine branch; else non-affine branch.\n", "\n", "- If affine (t1 = t2):\n", " - Test involution on two inputs:\n", " - Q7: X7 = 0^128; observe f(X7) = Y7\n", " - Q8: X8 = Y7; observe Z8 = f(X8)\n", " - Check whether Z8 = X7 (i.e., f(f(0)) = 0)\n", " - Q9: X9 = 1^128; observe Y9; Q10: f(Y9) to get Z10; check whether Z10 = X9\n", " - Decision after Q8–Q10:\n", " - If both Z8 = X7 and Z10 = X9, declare 5.\n", " - If any of these fails, declare 3.\n", "\n", "- If non-affine (t1 ≠ t2):\n", " - Test halves-invariance to pull out 4:\n", " - Q11: X11 = (a, b1) with a = 0^64, b1 = 0^64\n", " - Q12: X12 = (a, b2) with a = 0^64, b2 = 1^64\n", " - Compare first 64 bits of f(X11) and f(X12)\n", " - Decision after Q12:\n", " - If first halves match, declare 4.\n", " - If first halves differ, declare either 1 or 2 (no reliable unconditional method to distinguish them with a fixed small budget; see caveats below).\n", "\n", "- If you want a concrete final decision between 1 and 2 under this plan, you would need to invoke an unproven cryptographic assumption (PRP indistinguishability) or allow a far larger query budget. The plan above gives a robust, provably correct identification for 3, 4, 5, and a heuristic/PRP-based approach for 1 vs 2.\n", "\n", "Why this distinguishes cases 3–5 better than random guessing\n", "\n", "- Case 4 vs others: The first output half in case 4 depends only on the first input half. The test with a fixed a and two distinct b’s shows that the first halves are equal in 4 with probability exactly 1, whereas for a random 128‑bit permutation (case 1) or AES (case 2) this happens with probability 2^-64. With a single such pair of queries you isolate 4 with overwhelming probability (nearly certainty for 2^-64 error). In the affine branch you don’t even reach this step if the function is affine, so the 4 decision is cleanly separated from 1, 2, and 3 (and is not confused with 5 since 5 is affine).\n", "\n", "- Case 5 vs 3: Both are affine, but 5 has A = I. The two-invocation test f(f(x)) = x is a robust discriminator: for 5, it holds for all x; for most affine 3 cases (A ≠ I), f(f(x)) ≠ x for most x, and two independent probes already give a very high confidence. This separates 5 from 3 very reliably, while preserving the earlier affine/non-affine separation.\n", "\n", "- Case 1 and Case 2: With the plan above, you separate 4 from {1,2} using the half-factorization test. After that, distinguishing 1 from 2 cannot be guaranteed with a fixed finite budget in an unconditional way (see the next section). So, while the plan is excellent for 3, 4, 5, it leaves an intrinsic hardness for 1 vs 2 unless you assume standard cryptographic indistinguishability (which is a computational assumption, not an information-theoretic one).\n", "\n", "Information-theoretic notes and the 1 vs 2 distinction\n", "\n", "- Within the given 2000-query budget and with no extra assumptions, there is no known unconditional, information-theoretic procedure that can reliably distinguish a truly random permutation on 128‑bit strings (case 1) from AES-128 with an unknown key applied to a single 128‑bit block (case 2). Both are permutations of the same domain, and AES is designed to be indistinguishable from random in the standard cryptographic sense for polynomial-time adversaries. Without invoking cryptographic hardness assumptions, one cannot guarantee a bounded‑query distinguisher with non-negligible advantage.\n", "\n", "- If you adopt the standard cryptographic heuristic that AES with an unknown key is a pseudorandom permutation (PRP) indistinguishable from a true random permutation with any polynomially bounded adversary, then there is no bounded-test strategy (in the worst case) that has non-negligible distinguishing advantage between 1 and 2. The advantage would be negligible in the security parameter (128 bits here). Practically, that means: with 2000 queries you should not expect to distinguish 1 from 2 with non-negligible probability; the best you can do is rely on the small statistics you might observe, which are not reliable guarantees.\n", "\n", "- Therefore, in the present framing, you can claim:\n", " - We can reliably separate 3, 4, 5 from each other with a bounded number of queries (6 for the affine check, plus a couple of extra tests for 5 vs 3, plus the 4-vs-1/2 test described).\n", " - We cannot, in general, guarantee distinguishing 1 from 2 with a bounded, unconditional strategy. The most you can do is rely on cryptographic assumptions (PRP indistinguishability) to claim that any such distinction has only negligible advantage.\n", "\n", "- How to modify the problem to make 1 vs 2 distinguishable with bounded queries:\n", " - Remove the cryptographic indistinguishability ambiguity by giving the solver an explicit oracle for a second evaluation of f under a known, new key (i.e., allow reinitialization of the box to a fresh AES instance with a new random key for a second phase). With two unrelated AES instances, you could try to detect the difference between a fully random permutation and AES under a control key schedule. Or,\n", " - Fix the box to be a single random permutation versus a fixed but unknown‑key block cipher, and require that the box cannot simulate the PRP behavior across many inputs in a way indistinguishable from the uniform permutation. Either change yields a setting where you can derive a provable distinguishing strategy (or at least a bounded, provable advantage).\n", "\n", "Minimum number of queries and boundedness\n", "\n", "- The affine test (Stage 0 with 6 queries) plus the involution test (2–4 additional queries in the affine branch) plus the halves test for non-affine (2–3 queries) gives you a practical, concrete protocol that deterministically identifies 3, 4, and 5 with high probability, using on the order of 6–12 queries in total in typical runs.\n", "\n", "- In particular, you can guarantee:\n", " - Case 5 (f(x) = x ⊕ K) vs Case 3 (affine with A ≠ I): high confidence via f∘f tests.\n", " - Case 3 vs Case 4 vs Case 1: clear separation by affine test and then by the halves factorization test.\n", " - Case 1 vs Case 2: not guaranteed with a fixed, small bound; relies on standard cryptographic assumptions (see above).\n", "\n", "- If you want an explicit lower bound statement: No strictly bounded, unconditional strategy can guarantee distinguishing 1 from 2 with non-negligible probability in this setting, because both functions are (to within the natural model) indistinguishable by polynomially many queries. The only way to guarantee a distinction would be to impose a new assumption or change the problem (as described above).\n", "\n", "Putting it together as a concrete protocol\n", "\n", "- Phase 1 (6 queries): affine test\n", " - Query X1 = 0^128, X2 = 0^64||1^64, X3 = X1⊕X2\n", " - Query X4 = 0^64||1^64, X5 = 1^64||0^64, X6 = X4⊕X5\n", " - Compute t1 = f(X1) ⊕ f(X2) ⊕ f(X3), t2 = f(X4) ⊕ f(X5) ⊕ f(X6).\n", " - If t1 ≠ t2, non-affine branch; if t1 = t2, affine branch.\n", "\n", "- Phase 2a (affine branch): separate 5 from 3\n", " - Query X7 = 0^128; observe Y7 = f(X7)\n", " - Query X8 = Y7; observe Z8 = f(X8)\n", " - If Z8 = X7, test a second input X9 = 1^128; Query X10 = f(X9); Query X11 = f(X10); If X or both pass (Z8 = X7 and Z11 = X9), declare 5; else declare 3.\n", " - (Two tests are enough in practice to drive the error probability to negligible levels.)\n", "\n", "- Phase 2b (non-affine branch): separate 4 from {1,2}\n", " - Fixed a = 0^64, b1 = 0^64, b2 = 1^64\n", " - Query X12 = (a,b1), X13 = (a,b2)\n", " - If the first 64 bits of f(X12) and f(X13) are equal, declare 4; else proceed to Phase 2c.\n", " - Phase 2c to separate 1 vs 2 is not guaranteed unconditionally with bounded queries. You either accept a negligible advantage-based separation under PRP indistinguishability (i.e., no practical advantage) or you modify the problem as suggested above.\n", "\n", "Why this strategy satisfies the problem’s requirements\n", "\n", "- It gives a concrete, adaptive plan with explicit inputs for each query, and explicit decision rules on all possible transcripts you might observe (up to the probabilistic caveat for the 1 vs 2 distinction).\n", "- It provides a rigorous justification for why the affine test separates 3/5 from 1/2/4 with overwhelming probability, and why the half-by-half test separates 4 from the others in the non-affine branch.\n", "- It gives a principled argument for why, in the 1 vs 2 subproblem, you cannot guarantee a bounded success probability without additional cryptographic assumptions (hence the discussion about indistinguishability and possible problem modifications).\n", "\n", "If you want a completely foolproof identification of all five cases (including a provable 1 vs 2 distinction), here are two natural modifications you could consider\n", "\n", "- Change the problem to guarantee that the box’s 2 (AES) instance cannot be made indistinguishable from a random permutation under the given query budget (e.g., by providing side information about the key schedule, or requiring multiple keys and independent encryptions). Then you could design a polynomial-time distinguisher with non-negligible advantage; you could then separate 1 and 2 with a bounded query budget.\n", "\n", "- Alternatively, require the box to be reset with a fresh independently chosen permutation for each batch of queries (or to re-keyAES after every block). In that setting, you could exploit changes in mapping across batches to distinguish 1 (static random permutation) from 2 (AES under a fixed key), with guaranteed separation in a bounded number of queries.\n", "\n", "Bottom line\n", "\n", "- A concrete, practical strategy exists to reliably distinguish 3, 4, and 5 within a modest, bounded number of queries (6 for the affine test, plus a few extra tests). Distinguishing 1 from 2 with a small, fixed budget cannot be guaranteed unconditionally; it hinges on standard cryptographic assumptions about AES being indistinguishable from a random permutation. If you’re willing to accept such an assumption, Phase 2 between 1 and 2 becomes a routine PRP indistinguishability test; if not, you must either increase the budget dramatically or modify the problem as described." ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# The API we know well\n", "# I've updated this with the latest model, but it can take some time because it likes to think!\n", "# Replace the model with gpt-4.1-mini if you'd prefer not to wait 1-2 mins\n", "\n", "model_name = \"gpt-5-nano\"\n", "\n", "response = openai.chat.completions.create(model=model_name, messages=messages)\n", "answer = response.choices[0].message.content\n", "\n", "display(Markdown(answer))\n", "competitors.append(model_name)\n", "answers.append(answer)" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "ename": "BadRequestError", "evalue": "Error code: 400 - {'type': 'error', 'error': {'type': 'invalid_request_error', 'message': 'Your credit balance is too low to access the Anthropic API. Please go to Plans & Billing to upgrade or purchase credits.'}, 'request_id': 'req_011CbsGmsYxbnNi8t6t4LCqB'}", "output_type": "error", "traceback": [ "\u001b[31m---------------------------------------------------------------------------\u001b[39m", "\u001b[31mBadRequestError\u001b[39m Traceback (most recent call last)", "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[19]\u001b[39m\u001b[32m, line 6\u001b[39m\n\u001b[32m 3\u001b[39m model_name = \u001b[33m\"\u001b[39m\u001b[33mclaude-sonnet-4-5\u001b[39m\u001b[33m\"\u001b[39m\n\u001b[32m 5\u001b[39m claude = Anthropic()\n\u001b[32m----> \u001b[39m\u001b[32m6\u001b[39m response = \u001b[43mclaude\u001b[49m\u001b[43m.\u001b[49m\u001b[43mmessages\u001b[49m\u001b[43m.\u001b[49m\u001b[43mcreate\u001b[49m\u001b[43m(\u001b[49m\u001b[43mmodel\u001b[49m\u001b[43m=\u001b[49m\u001b[43mmodel_name\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mmessages\u001b[49m\u001b[43m=\u001b[49m\u001b[43mmessages\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mmax_tokens\u001b[49m\u001b[43m=\u001b[49m\u001b[32;43m1000\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[32m 7\u001b[39m answer = response.content[\u001b[32m0\u001b[39m].text\n\u001b[32m 9\u001b[39m display(Markdown(answer))\n", "\u001b[36mFile \u001b[39m\u001b[32mc:\\Users\\060110975\\OneDrive - Kemenkeu\\Training\\Agentic AI ed donner\\.venv\\Lib\\site-packages\\anthropic\\_utils\\_utils.py:282\u001b[39m, in \u001b[36mrequired_args..inner..wrapper\u001b[39m\u001b[34m(*args, **kwargs)\u001b[39m\n\u001b[32m 280\u001b[39m msg = \u001b[33mf\u001b[39m\u001b[33m\"\u001b[39m\u001b[33mMissing required argument: \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mquote(missing[\u001b[32m0\u001b[39m])\u001b[38;5;132;01m}\u001b[39;00m\u001b[33m\"\u001b[39m\n\u001b[32m 281\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mTypeError\u001b[39;00m(msg)\n\u001b[32m--> \u001b[39m\u001b[32m282\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mfunc\u001b[49m\u001b[43m(\u001b[49m\u001b[43m*\u001b[49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m*\u001b[49m\u001b[43m*\u001b[49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n", "\u001b[36mFile \u001b[39m\u001b[32mc:\\Users\\060110975\\OneDrive - Kemenkeu\\Training\\Agentic AI ed donner\\.venv\\Lib\\site-packages\\anthropic\\resources\\messages\\messages.py:930\u001b[39m, in \u001b[36mMessages.create\u001b[39m\u001b[34m(self, max_tokens, messages, model, metadata, service_tier, stop_sequences, stream, system, temperature, thinking, tool_choice, tools, top_k, top_p, extra_headers, extra_query, extra_body, timeout)\u001b[39m\n\u001b[32m 923\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m model \u001b[38;5;129;01min\u001b[39;00m DEPRECATED_MODELS:\n\u001b[32m 924\u001b[39m warnings.warn(\n\u001b[32m 925\u001b[39m \u001b[33mf\u001b[39m\u001b[33m\"\u001b[39m\u001b[33mThe model \u001b[39m\u001b[33m'\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mmodel\u001b[38;5;132;01m}\u001b[39;00m\u001b[33m'\u001b[39m\u001b[33m is deprecated and will reach end-of-life on \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mDEPRECATED_MODELS[model]\u001b[38;5;132;01m}\u001b[39;00m\u001b[33m.\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[33mPlease migrate to a newer model. Visit https://docs.anthropic.com/en/docs/resources/model-deprecations for more information.\u001b[39m\u001b[33m\"\u001b[39m,\n\u001b[32m 926\u001b[39m \u001b[38;5;167;01mDeprecationWarning\u001b[39;00m,\n\u001b[32m 927\u001b[39m stacklevel=\u001b[32m3\u001b[39m,\n\u001b[32m 928\u001b[39m )\n\u001b[32m--> \u001b[39m\u001b[32m930\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43m_post\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m 931\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43m/v1/messages\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[32m 932\u001b[39m \u001b[43m \u001b[49m\u001b[43mbody\u001b[49m\u001b[43m=\u001b[49m\u001b[43mmaybe_transform\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m 933\u001b[39m \u001b[43m \u001b[49m\u001b[43m{\u001b[49m\n\u001b[32m 934\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mmax_tokens\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mmax_tokens\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 935\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mmessages\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mmessages\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 936\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mmodel\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mmodel\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 937\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mmetadata\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mmetadata\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 938\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mservice_tier\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mservice_tier\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 939\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mstop_sequences\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mstop_sequences\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 940\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mstream\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mstream\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 941\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43msystem\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43msystem\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 942\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mtemperature\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mtemperature\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 943\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mthinking\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mthinking\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 944\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mtool_choice\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mtool_choice\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 945\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mtools\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mtools\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 946\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mtop_k\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mtop_k\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 947\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mtop_p\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mtop_p\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 948\u001b[39m \u001b[43m \u001b[49m\u001b[43m}\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 949\u001b[39m \u001b[43m \u001b[49m\u001b[43mmessage_create_params\u001b[49m\u001b[43m.\u001b[49m\u001b[43mMessageCreateParamsStreaming\u001b[49m\n\u001b[32m 950\u001b[39m \u001b[43m \u001b[49m\u001b[38;5;28;43;01mif\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mstream\u001b[49m\n\u001b[32m 951\u001b[39m \u001b[43m \u001b[49m\u001b[38;5;28;43;01melse\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mmessage_create_params\u001b[49m\u001b[43m.\u001b[49m\u001b[43mMessageCreateParamsNonStreaming\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 952\u001b[39m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 953\u001b[39m \u001b[43m \u001b[49m\u001b[43moptions\u001b[49m\u001b[43m=\u001b[49m\u001b[43mmake_request_options\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m 954\u001b[39m \u001b[43m \u001b[49m\u001b[43mextra_headers\u001b[49m\u001b[43m=\u001b[49m\u001b[43mextra_headers\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mextra_query\u001b[49m\u001b[43m=\u001b[49m\u001b[43mextra_query\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mextra_body\u001b[49m\u001b[43m=\u001b[49m\u001b[43mextra_body\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtimeout\u001b[49m\u001b[43m=\u001b[49m\u001b[43mtimeout\u001b[49m\n\u001b[32m 955\u001b[39m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 956\u001b[39m \u001b[43m \u001b[49m\u001b[43mcast_to\u001b[49m\u001b[43m=\u001b[49m\u001b[43mMessage\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 957\u001b[39m \u001b[43m \u001b[49m\u001b[43mstream\u001b[49m\u001b[43m=\u001b[49m\u001b[43mstream\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;129;43;01mor\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mFalse\u001b[39;49;00m\u001b[43m,\u001b[49m\n\u001b[32m 958\u001b[39m \u001b[43m \u001b[49m\u001b[43mstream_cls\u001b[49m\u001b[43m=\u001b[49m\u001b[43mStream\u001b[49m\u001b[43m[\u001b[49m\u001b[43mRawMessageStreamEvent\u001b[49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 959\u001b[39m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n", "\u001b[36mFile \u001b[39m\u001b[32mc:\\Users\\060110975\\OneDrive - Kemenkeu\\Training\\Agentic AI ed donner\\.venv\\Lib\\site-packages\\anthropic\\_base_client.py:1324\u001b[39m, in \u001b[36mSyncAPIClient.post\u001b[39m\u001b[34m(self, path, cast_to, body, options, files, stream, stream_cls)\u001b[39m\n\u001b[32m 1310\u001b[39m \u001b[38;5;28;01mdef\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34mpost\u001b[39m(\n\u001b[32m 1311\u001b[39m \u001b[38;5;28mself\u001b[39m,\n\u001b[32m 1312\u001b[39m path: \u001b[38;5;28mstr\u001b[39m,\n\u001b[32m (...)\u001b[39m\u001b[32m 1319\u001b[39m stream_cls: \u001b[38;5;28mtype\u001b[39m[_StreamT] | \u001b[38;5;28;01mNone\u001b[39;00m = \u001b[38;5;28;01mNone\u001b[39;00m,\n\u001b[32m 1320\u001b[39m ) -> ResponseT | _StreamT:\n\u001b[32m 1321\u001b[39m opts = FinalRequestOptions.construct(\n\u001b[32m 1322\u001b[39m method=\u001b[33m\"\u001b[39m\u001b[33mpost\u001b[39m\u001b[33m\"\u001b[39m, url=path, json_data=body, files=to_httpx_files(files), **options\n\u001b[32m 1323\u001b[39m )\n\u001b[32m-> \u001b[39m\u001b[32m1324\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m cast(ResponseT, \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43mrequest\u001b[49m\u001b[43m(\u001b[49m\u001b[43mcast_to\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mopts\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mstream\u001b[49m\u001b[43m=\u001b[49m\u001b[43mstream\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mstream_cls\u001b[49m\u001b[43m=\u001b[49m\u001b[43mstream_cls\u001b[49m\u001b[43m)\u001b[49m)\n", "\u001b[36mFile \u001b[39m\u001b[32mc:\\Users\\060110975\\OneDrive - Kemenkeu\\Training\\Agentic AI ed donner\\.venv\\Lib\\site-packages\\anthropic\\_base_client.py:1112\u001b[39m, in \u001b[36mSyncAPIClient.request\u001b[39m\u001b[34m(self, cast_to, options, stream, stream_cls)\u001b[39m\n\u001b[32m 1109\u001b[39m err.response.read()\n\u001b[32m 1111\u001b[39m log.debug(\u001b[33m\"\u001b[39m\u001b[33mRe-raising status error\u001b[39m\u001b[33m\"\u001b[39m)\n\u001b[32m-> \u001b[39m\u001b[32m1112\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;28mself\u001b[39m._make_status_error_from_response(err.response) \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[32m 1114\u001b[39m \u001b[38;5;28;01mbreak\u001b[39;00m\n\u001b[32m 1116\u001b[39m \u001b[38;5;28;01massert\u001b[39;00m response \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m, \u001b[33m\"\u001b[39m\u001b[33mcould not resolve response (should never happen)\u001b[39m\u001b[33m\"\u001b[39m\n", "\u001b[31mBadRequestError\u001b[39m: Error code: 400 - {'type': 'error', 'error': {'type': 'invalid_request_error', 'message': 'Your credit balance is too low to access the Anthropic API. Please go to Plans & Billing to upgrade or purchase credits.'}, 'request_id': 'req_011CbsGmsYxbnNi8t6t4LCqB'}" ] } ], "source": [ "# Anthropic has a slightly different API, and Max Tokens is required\n", "\n", "model_name = \"claude-sonnet-4-5\"\n", "\n", "claude = Anthropic()\n", "response = claude.messages.create(model=model_name, messages=messages, max_tokens=1000)\n", "answer = response.content[0].text\n", "\n", "display(Markdown(answer))\n", "competitors.append(model_name)\n", "answers.append(answer)" ] }, { "cell_type": "code", "execution_count": 50, "metadata": {}, "outputs": [ { "data": { "text/markdown": [ "The task is to design an adaptive querying strategy to distinguish between five types of 128-bit functions with a budget of 2,000 queries, using only paper reasoning.\n", "\n", "Let's first analyze the key properties of each function type:\n", "\n", "1. **Random Permutation (RP):** A truly random, bijective mapping. No discernible structure or pattern for a small number of queries.\n", "2. **AES-128 (ECB mode) (AES):** A pseudorandom permutation (PRP). It's computationally indistinguishable from a random permutation for any adversary with limited computational resources and a reasonable number of queries.\n", "3. **Affine function \\(f(x)=A x \\oplus b\\):** A linear transformation \\(Ax\\) over \\(\\mathbb{F}_2^{128}\\) (where \\(A\\) is an invertible \\(128\\times128\\) binary matrix) followed by an XOR with a constant \\(b\\).\n", " * **Key Property:** For any inputs \\(x_1, x_2\\), \\(f(x_1) \\oplus f(x_2) = A(x_1 \\oplus x_2)\\). This implies that if \\(x_1 \\oplus x_2 = x_3 \\oplus x_4\\), then \\(f(x_1) \\oplus f(x_2) = f(x_3) \\oplus f(x_4)\\). More specifically, for a fixed \\(\\Delta \\ne 0\\), the output difference \\(f(x \\oplus \\Delta) \\oplus f(x)\\) is constant for all \\(x\\).\n", "4. **Split Random Permutation \\(f(x)=g(x_L)\\,\\|\\,h(x_R)\\):** The input \\(x\\) is split into a 64-bit left part \\(x_L\\) and a 64-bit right part \\(x_R\\). The output is formed by concatenating \\(g(x_L)\\) and \\(h(x_R)\\), where \\(g\\) and \\(h\\) are independent random permutations on 64-bit strings.\n", " * **Key Property:** If \\(x_L\\) is held constant, then the left 64 bits of the output \\(g(x_L)\\) remain constant, regardless of changes in \\(x_R\\). Similarly, if \\(x_R\\) is held constant, the right 64 bits of the output \\(h(x_R)\\) remain constant.\n", "5. **XOR with a fixed key \\(f(x)=x\\oplus K\\):** A very simple affine function where \\(A\\) is the identity matrix.\n", " * **Key Property:** For any inputs \\(x_1, x_2\\), \\(f(x_1) \\oplus f(x_2) = (x_1 \\oplus K) \\oplus (x_2 \\oplus K) = x_1 \\oplus x_2\\). The output difference is always equal to the input difference.\n", "\n", "**Strategy Overview:**\n", "\n", "The strategy will involve a sequence of adaptive tests, moving from the most specific and easily detectable properties (XOR) to more general ones (Affine, Split RP). If none of these specific patterns are detected, the function is classified as either AES or Random Permutation, which are considered indistinguishable under the given constraints. Each test is designed to exploit a unique structural property that is highly unlikely to occur by chance in other function types (especially RP or AES).\n", "\n", "**Notation:**\n", "* `Q(x)`: Submit input `x` and observe the output.\n", "* `y[L]`: The first 64 bits of a 128-bit value `y`.\n", "* `y[R]`: The last 64 bits of a 128-bit value `y`.\n", "\n", "---\n", "\n", "**Detailed Adaptive Querying Strategy:**\n", "\n", "We will use a total of **9 queries** to identify Cases 3, 4, or 5 with very high probability. If none of these are identified, we classify it as Case 1 or 2.\n", "\n", "**Phase 1: Test for Case 5 (XOR with a fixed key)**\n", "This is the strongest structural property.\n", "1. **Query 1:** Set \\(x_1 = 0^{128}\\) (all zeros). Query \\(Q(x_1)\\), observe \\(y_1\\).\n", "2. **Query 2:** Set \\(x_2 = 0^{127}1\\) (value 1). Query \\(Q(x_2)\\), observe \\(y_2\\).\n", "3. **Query 3:** Set \\(x_3 = 0^{126}10\\) (value 2). Query \\(Q(x_3)\\), observe \\(y_3\\).\n", "\n", "* **Decision Rule for XOR:**\n", " If \\((y_2 \\oplus y_1 = x_2 \\oplus x_1)\\) AND \\((y_3 \\oplus y_1 = x_3 \\oplus x_1)\\):\n", " **Declare Case 5 (XOR)**. Stop.\n", "* **Justification:** For \\(f(x)=x \\oplus K\\), these conditions must hold (e.g., \\(f(1) \\oplus f(0) = (1 \\oplus K) \\oplus (0 \\oplus K) = 1 \\oplus 0 = 1\\)). For a random permutation, AES, affine function with \\(A \\ne I\\), or split RP, the probability of satisfying these two conditions is approximately \\((1/2^{128}) \\times (1/2^{128}) = 1/2^{256}\\). This is an astronomically low probability of false positive.\n", "\n", "**Phase 2: Test for Case 3 (Affine function)**\n", "This phase is executed only if Case 5 was NOT identified in Phase 1.\n", "4. **Query 4:** Choose a fixed difference \\(\\Delta = 0^{125}100\\) (value 4). This value is distinct from \\(x_1, x_2, x_3\\). Set \\(x_4 = x_1 \\oplus \\Delta = 0 \\oplus 4 = 4\\). Query \\(Q(x_4)\\), observe \\(y_4\\).\n", "5. **Query 5:** Set \\(x_5 = x_2 \\oplus \\Delta = 1 \\oplus 4 = 5\\). Query \\(Q(x_5)\\), observe \\(y_5\\).\n", "6. **Query 6:** Set \\(x_6 = x_3 \\oplus \\Delta = 2 \\oplus 4 = 6\\). Query \\(Q(x_6)\\), observe \\(y_6\\).\n", " (All inputs \\(x_1 \\dots x_6\\) are distinct: 0, 1, 2, 4, 5, 6).\n", "\n", "* **Decision Rule for Affine:**\n", " Let \\(D_0 = y_4 \\oplus y_1\\). (This is the candidate value for \\(A\\Delta\\)).\n", " If \\((y_5 \\oplus y_2 = D_0)\\) AND \\((y_6 \\oplus y_3 = D_0)\\):\n", " **Declare Case 3 (Affine)**. Stop.\n", "* **Justification:** For \\(f(x)=Ax \\oplus b\\), the value \\(f(x \\oplus \\Delta) \\oplus f(x)\\) must be constant for a fixed \\(\\Delta\\) (it equals \\(A\\Delta\\)). So, \\(y_4 \\oplus y_1\\) must equal \\(y_5 \\oplus y_2\\), which must equal \\(y_6 \\oplus y_3\\). The probability of these two equalities holding by chance for a random permutation, AES, or split RP is approximately \\((1/2^{128}) \\times (1/2^{128}) = 1/2^{256}\\).\n", "\n", "**Phase 3: Test for Case 4 (Split Random Permutation)**\n", "This phase is executed only if Case 5 and Case 3 were NOT identified.\n", "7. **Query 7:** Define \\(\\Delta_L = (1 \\ll 127)\\), which is the most significant bit of the left 64 bits set to 1. Set \\(x_7 = x_1 \\oplus \\Delta_L = \\Delta_L\\). Query \\(Q(x_7)\\), observe \\(y_7\\).\n", "8. **Query 8:** Define \\(\\Delta_R = (1 \\ll 63)\\), which is the most significant bit of the right 64 bits set to 1. Set \\(x_8 = x_1 \\oplus \\Delta_R = \\Delta_R\\). Query \\(Q(x_8)\\), observe \\(y_8\\).\n", "9. **Query 9:** Set \\(x_9 = x_1 \\oplus \\Delta_L \\oplus \\Delta_R = \\Delta_L \\oplus \\Delta_R\\). Query \\(Q(x_9)\\), observe \\(y_9\\).\n", " (All inputs \\(x_1 \\dots x_9\\) are distinct: 0, 1, 2, 4, 5, 6, \\(\\Delta_L\\), \\(\\Delta_R\\), \\(\\Delta_L \\oplus \\Delta_R\\)).\n", "\n", "* **Decision Rule for Split RP:**\n", " If \\((y_7[R] = y_1[R])\\) AND \\((y_8[L] = y_1[L])\\) AND \\((y_9[L] = y_7[L])\\) AND \\((y_9[R] = y_8[R])\\):\n", " **Declare Case 4 (Split RP)**. Stop.\n", "* **Justification:** For \\(f(x)=g(x_L)\\,\\|\\,h(x_R)\\):\n", " * \\(x_R(x_7) = x_R(\\Delta_L) = 0\\), and \\(x_R(x_1) = x_R(0) = 0\\). So \\(y_7[R] = h(0)\\) and \\(y_1[R] = h(0)\\). They must be equal. (Prob for RP/AES/Affine: \\(1/2^{64}\\)).\n", " * \\(x_L(x_8) = x_L(\\Delta_R) = 0\\), and \\(x_L(x_1) = x_L(0) = 0\\). So \\(y_8[L] = g(0)\\) and \\(y_1[L] = g(0)\\). They must be equal. (Prob for RP/AES/Affine: \\(1/2^{64}\\)).\n", " * \\(x_L(x_9) = x_L(\\Delta_L \\oplus \\Delta_R) = x_L(\\Delta_L)\\). So \\(y_9[L] = g(x_L(\\Delta_L)) = y_7[L]\\). This condition holds with probability 1 for Split RP. For RP/AES/Affine, \\(y_9[L]\\) would be a new random 64-bit value, so probability of match is \\(1/2^{64}\\).\n", " * \\(x_R(x_9) = x_R(\\Delta_L \\oplus \\Delta_R) = x_R(\\Delta_R)\\). So \\(y_9[R] = h(x_R(\\Delta_R)) = y_8[R]\\). This condition also holds with probability 1 for Split RP. For RP/AES/Affine, \\(y_9[R]\\) would be a new random 64-bit value, so probability of match is \\(1/2^{64}\\).\n", " The combined probability of all four conditions occurring by chance for RP/AES/Affine is approximately \\((1/2^{64})^4 = 1/2^{256}\\).\n", "\n", "**Phase 4: Indistinguishable Cases (RP or AES-128)**\n", "This phase is executed only if none of the specific patterns were identified in Phases 1-3.\n", "\n", "* **Decision Rule for RP/AES:**\n", " If none of the above conditions are met after 9 queries:\n", " **Declare Cases 1 or 2 (Indistinguishable: Random Permutation or AES-128)**. Stop.\n", "* **Justification:**\n", " * **Computational Indistinguishability:** AES is designed to be a strong pseudorandom permutation (PRP). For an adversary with \"paper reasoning\" (i.e., no computational resources to perform complex statistical analyses) and a limited number of queries (2,000 queries is very small compared to the \\(2^{128}\\) domain size), AES-128 is computationally indistinguishable from a truly random permutation. Any simple statistical test that could be performed manually (e.g., checking for immediate collisions or very short cycles) would fail to distinguish them with 2,000 queries due to the vast domain.\n", " * **Information-Theoretic Indistinguishability:** There is no known structural property of AES that would manifest within 2,000 queries (or even a much larger number, like \\(2^{64}\\)) that is simple enough to be detected by \"paper reasoning\" and not also be present in a random permutation with high probability, or ruled out by previous tests. The specific structural properties of AES (e.g., S-boxes, mix columns, key schedule) are designed to diffuse input changes rapidly, preventing simple patterns from emerging.\n", "\n", "---\n", "\n", "**Summary of Queries and Success Probability:**\n", "\n", "* **Minimum Queries:** 3 (if XOR), 6 (if Affine), or 9 (if Split RP or RP/AES).\n", "* **Maximum Queries Used:** 9. The strategy is well within the 2,000 query budget.\n", "* **Success Probability:**\n", " * For XOR, Affine, and Split RP functions, the probability of correctly identifying them is extremely high (error probability of roughly \\(1/2^{256}\\) for each, due to false positives from other types).\n", " * For Random Permutation and AES-128, the strategy groups them as \"indistinguishable\". This maximizes success probability because, given the constraints (2,000 queries, paper reasoning), there's no reliable way to tell them apart. If a single distinct answer is required for all five, then the success probability for these two cases would be very low (e.g., 50% if forced to guess), as there are no distinguishing features discoverable under the given conditions.\n", "\n", "---\n", "\n", "**Modifications to make AES/RP distinguishable:**\n", "\n", "To make AES-128 and a uniformly random permutation distinguishable with a high success probability, one would need to alter the problem constraints significantly:\n", "\n", "1. **Increased Query Budget:** A much larger query budget, ideally in the order of \\(2^{64}\\) or more, would allow an adversary to perform statistical tests (like chi-squared tests on output distributions, birthday attacks on internal states, or more advanced cryptanalytic techniques) that could detect non-randomness in AES.\n", "2. **Computational Resources:** Allowing computational resources would enable an adversary to process and analyze the outputs of thousands or millions of queries, looking for subtle statistical biases or patterns that are characteristic of AES but not of a truly random function. \"Paper reasoning\" explicitly rules out such analysis.\n", "3. **Known Plaintext/Ciphertext Pairs for AES:** If the adversary had access to known plaintext/ciphertext pairs for the specific AES key, they could compare them against the black box's output, thus confirming AES.\n", "4. **Side-Channel Information:** Access to side-channel information (e.g., timing, power consumption, electromagnetic radiation) during the black box's computation of \\(f(x)\\) could easily distinguish AES from a hypothetical \"truly random\" hardware implementation." ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "gemini = OpenAI(api_key=google_api_key, base_url=\"https://generativelanguage.googleapis.com/v1beta/openai/\")\n", "model_name = \"gemini-2.5-flash\"\n", "#model_name = \"gemini-2.0-flash\"\n", "\n", "\n", "response = gemini.chat.completions.create(model=model_name, messages=messages)\n", "answer = response.choices[0].message.content\n", "\n", "display(Markdown(answer))\n", "competitors.append(model_name)\n", "answers.append(answer)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "deepseek = OpenAI(api_key=deepseek_api_key, base_url=\"https://api.deepseek.com/v1\")\n", "model_name = \"deepseek-chat\"\n", "\n", "response = deepseek.chat.completions.create(model=model_name, messages=messages)\n", "answer = response.choices[0].message.content\n", "\n", "display(Markdown(answer))\n", "competitors.append(model_name)\n", "answers.append(answer)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Updated with the latest Open Source model from OpenAI\n", "\n", "groq = OpenAI(api_key=groq_api_key, base_url=\"https://api.groq.com/openai/v1\")\n", "model_name = \"openai/gpt-oss-120b\"\n", "\n", "response = groq.chat.completions.create(model=model_name, messages=messages)\n", "answer = response.choices[0].message.content\n", "\n", "display(Markdown(answer))\n", "competitors.append(model_name)\n", "answers.append(answer)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## For the next cell, we will use Ollama\n", "\n", "Ollama runs a local web service that gives an OpenAI compatible endpoint, \n", "and runs models locally using high performance C++ code.\n", "\n", "If you don't have Ollama, install it here by visiting https://ollama.com then pressing Download and following the instructions.\n", "\n", "After it's installed, you should be able to visit here: http://localhost:11434 and see the message \"Ollama is running\"\n", "\n", "You might need to restart Cursor (and maybe reboot). Then open a Terminal (control+\\`) and run `ollama serve`\n", "\n", "Useful Ollama commands (run these in the terminal, or with an exclamation mark in this notebook):\n", "\n", "`ollama pull ` downloads a model locally \n", "`ollama ls` lists all the models you've downloaded \n", "`ollama rm ` deletes the specified model from your downloads" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", " \n", " \n", " \n", " \n", "
\n", " \n", " \n", "

Super important - ignore me at your peril!

\n", " The model called llama3.3 is FAR too large for home computers - it's not intended for personal computing and will consume all your resources! Stick with the nicely sized llama3.2 or llama3.2:1b and if you want larger, try llama3.1 or smaller variants of Qwen, Gemma, Phi or DeepSeek. See the the Ollama models page for a full list of models and sizes.\n", " \n", "
" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "!ollama pull llama3.2" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "ollama = OpenAI(base_url='http://localhost:11434/v1', api_key='ollama')\n", "model_name = \"llama3.2\"\n", "\n", "response = ollama.chat.completions.create(model=model_name, messages=messages)\n", "answer = response.choices[0].message.content\n", "\n", "display(Markdown(answer))\n", "competitors.append(model_name)\n", "answers.append(answer)" ] }, { "cell_type": "code", "execution_count": 54, "metadata": {}, "outputs": [ { "data": { "text/markdown": [ "### Executive Summary\n", "To distinguish between the five cases with the highest possible success probability, only **4 adaptive queries** are sufficient. This strategy exploits the specific algebraic and structural properties of each function to rule out candidates efficiently.\n", "\n", "The identification follows a strict hierarchy:\n", "1. **Case 5 (XOR Mask):** Detected via constant differential properties.\n", "2. **Case 4 (Split Permutation):** Detected via partial independence (changing half the input does not change the other half of the output).\n", "3. **Case 3 (Affine):** Detected via additive relationships (XOR sums of inputs equal XOR sums of outputs).\n", "4. **Cases 1 & 2 (Random Perm / AES):** These are information-theoretically indistinguishable within the given budget.\n", "\n", "---\n", "\n", "### Detailed Adaptive Querying Strategy\n", "\n", "#### Phase 1: Initialization\n", "We begin by defining four basis vectors to probe the function's linearity and bit-dependency.\n", "1. **Query 1 ($x_0$):** Submit `00...00` (128 zeros). Receive $y_0$.\n", "2. **Query 2 ($x_1$):** Submit `10...00` (Bit 127 set; Upper Half). Receive $y_1$.\n", "3. **Query 3 ($x_2$):** Submit `00...01` (Bit 0 set; Lower Half). Receive $y_2$.\n", "\n", "At this point, we have evaluated the function at the origin and at two orthogonal unit vectors.\n", "\n", "#### Phase 2: Sequential Decision Rules\n", "\n", "**Step 1: Check for Case 5 (XOR Mask)**\n", "A function in Case 5 satisfies $f(x) = x \\oplus K$. Thus, $f(x) \\oplus x$ must equal the constant vector $K$.\n", "* **Compute Candidate Keys:**\n", " * $K_0 = y_0 \\oplus 0 = y_0$\n", " * $K_1 = y_1 \\oplus x_1$\n", " * $K_2 = y_2 \\oplus x_2$\n", "* **Decision Rule:**\n", " * If **$K_0 = K_1 = K_2$**, identify **Case 5**. Terminate.\n", " * Otherwise, proceed to Step 2.\n", " * *Reasoning:* In Case 5, this equality holds with probability 1. In all other cases, the probability of this happening for 3 points is roughly $2^{-384}$.\n", "\n", "**Step 2: Check for Case 4 (Split Permutation)**\n", "A function in Case 4 is separable: $f(x_L, x_R) = (\\pi_1(x_L), \\pi_2(x_R))$.\n", "* **Property:** Changing the Upper Input ($x_L$) should **not** affect the Lower Output ($Y_R$). Conversely, changing the Lower Input ($x_R$) should **not** affect the Upper Output ($Y_L$).\n", "* **Action:** Compare the halves of the received outputs.\n", " 1. Extract the Lower 64 bits of $y_1$ and $y_0$.\n", " 2. Extract the Upper 64 bits of $y_2$ and $y_0$.\n", "* **Decision Rule:**\n", " * If (Lower half of $y_1$ == Lower half of $y_0$) **AND** (Upper half of $y_2$ == Upper half of $y_0$), identify **Case 4**. Terminate.\n", " * Otherwise, proceed to Step 3.\n", " * *Reasoning:* This specific structural independence holds for Case 4. It fails for random or fully mixed functions with probability $1 - 2^{-64}$.\n", "\n", "**Step 3: Check for Case 3 (Affine Transformation)**\n", "If the first two tests fail, we check for linearity. Case 3 functions satisfy $f(A \\oplus B) = f(A) \\oplus f(B) \\oplus f(0)$.\n", "* **Action:**\n", " 1. Compute the target XOR sum: $Target = y_0 \\oplus y_1 \\oplus y_2$.\n", " 2. **Query 4 ($x_3$):** Submit $x_1 \\oplus x_2$ (bits 127 and 0 set). Receive $y_3$.\n", "* **Decision Rule:**\n", " * If **$y_3 = Target$**, identify **Case 3**. Terminate.\n", " * Otherwise, proceed to Final Assessment.\n", " * *Reasoning:* This check verifies the affine homomorphism property. While Case 5 also satisfies this, it was ruled out in Step 1.\n", "\n", "**Final Assessment: Case 1 or 2**\n", "If all structural checks fail, the function lacks the algebraic structure of 3, 4, or 5.\n", "* **Identification:** **Case 1 (Random Permutation) or Case 2 (AES-128).**\n", "* *Reasoning:* Both are permutations with no detectable bias under this query budget.\n", "\n", "---\n", "\n", "### Justification\n", "\n", "1. **Case 5 (Linear/XOR):** Defined by a constant differential. Any deviation in $f(x) \\oplus x$ rules it out.\n", "2. **Case 4 (Separable):** Defined by independent sub-spaces. Testing coordinate independence is a definitive structural signature.\n", "3. **Case 3 (Affine):** Defined by linear superposition. The XOR-additivity check $f(x \\oplus y) \\oplus f(x) \\oplus f(y) \\oplus f(0) = 0$ is a rigorous mathematical test for affine maps.\n", "4. **Cases 1 vs 2:** Distinguishability relies on finding statistical deviations from randomness. AES-128 is a Pseudorandom Permutation (PRP); its outputs are computationally indistinguishable from a truly Random Permutation. With a budget of 2,000 queries (significantly below the birthday bound of $2^{64}$), no information-theoretic distinguisher exists.\n", "\n", "---\n", "\n", "### Indistinguishability of Cases 1 and 2\n", "\n", "**Why they are indistinguishable:**\n", "Under the given constraints, Case 1 and Case 2 are information-theoretically indistinguishable. A secure block cipher like AES is designed specifically to mimic a Random Permutation. With $N=2000$ queries, the statistical distance between the output distribution of AES and a Uniform Random Permutation is vanishingly small (advantage $\\approx N^2/2^{128}$).\n", "\n", "**Proposed Problem Modifications to Enable Distinction:**\n", "To make Case 1 distinguishable from Case 2, one could:\n", "1. **Increase Query Budget Exponentially:** Raising the query limit to $\\ge 2^{64}$ would allow the observation of collisions or statistical biases inherent in the construction, though this remains computationally difficult.\n", "2. **Alter Case 1 (Null Hypothesis):** Replace \"Random Permutation\" with **\"Random Function\"**. A Random Function allows collisions ($f(x) = f(y)$ for $x \\neq y$), while AES (Case 2) remains a permutation. Checking for output collisions would instantly identify Case 1.\n", "3. **Alter Case 2 (Weak Cipher):** Specify AES with a **weak key** (e.g., $K=0$) or a known variation with a known distinguisher (e.g., a specific linear trail), allowing manual verification." ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# === SumoPod API Test ===\n", "# Re-load env vars to pick up the new key\n", "# load_dotenv(override=True)\n", "sumopod_api_key = os.getenv(\"SUMOPOD_API_KEY\")\n", "# Create a SumoPod client using OpenAI SDK with SumoPod's base URL\n", "sumopod = OpenAI(\n", " api_key=sumopod_api_key,\n", " base_url=\"https://ai.sumopod.com/v1\"\n", ")\n", "model_name=\"qwen3.6-flash\"\n", "# Test it with the same question used for other models\n", "\n", "response = sumopod.chat.completions.create(model=model_name, messages=messages)\n", "answer = response.choices[0].message.content\n", "\n", "display(Markdown(answer))\n", "competitors.append(model_name)\n", "answers.append(answer)" ] }, { "cell_type": "code", "execution_count": 55, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "['gpt-5-nano', 'gemini-2.5-flash', 'qwen3.6-flash']\n", "[\"Below is a concrete, adaptive strategy that (i) uses a bounded number of 128‑bit queries, (ii) works for all five possibilities with high probability, and (iii) makes explicit the transcript-based decision rules. I also include a careful discussion of what can and cannot be guaranteed with the given budget, and how you could modify the problem if you want a provable distinction in all five cases.\\n\\nHigh-level plan (what we try to separate and why)\\n\\n- A quick affine/linear test lets us separate the “affine” family f(x) = A x ⊕ b from all the genuinely non‑affine possibilities (cases 1, 2, 4). This immediately distinguishes 5 (A = I, b = K) from all non‑affine cases with very high probability, and separates 3 (A arbitrary invertible) from 5.\\n\\n- If we flag affine and the test is consistent with A = I (the XOR-with-a-constant family), we can separate case 5 from the rest of the affine family using a small extra test (involution style): for case 5, f∘f = id; for generic affine (case 3 with A ≠ I), f∘f is not the identity for almost all inputs (and we can detect this with a couple of probes). This gives a robust way to distinguish 5 from 3, while still keeping error probability negligible.\\n\\n- If we flag non-affine (i.e., not in affine form), we can separate case 4 from cases 1 and 2 using a simple “factorization by halves” observation: in case 4, the first output half depends only on the first input half, and the second output half depends only on the second input half (g and h are independent 64‑bit permutations). In contrast, a random 128‑bit permutation (case 1) and AES in ECB (case 2) do not factorize this way. With a single carefully chosen pair of queries having the same first input half but different second halves, the first output half should be identical for 4 but not for 1 or 2 with overwhelming probability (2^-64 type small error). This lets us separate 4 from {1,2} with high confidence.\\n\\n- Distinguishing 1 vs 2 (uniform random permutation vs AES with an unknown key) cannot be guaranteed to succeed with a bounded, small query budget under standard cryptographic indistinguishability assumptions; both look like random permutations on the 128‑bit domain to any polynomially bounded test. I flag this explicitly and explain how you could modify the task if you want a provable separation in all five cases.\\n\\nNow the detailed strategy\\n\\n1) Meet-the-affine test (to pull case 3, 5 apart from 1, 2, 4)\\n\\n- Query preparation (6 inputs use, two independent triple tests to check affine structure):\\n - Let X1 = 0^128 (all zero 128 bits).\\n - Let X2 = 0^64 || 1^64 (first 64 bits zero, last 64 bits all ones).\\n - Let X3 = X1 ⊕ X2 = 0^64 || 1^64 (note X3 ≠ X1, X3 ≠ X2).\\n\\n - Let X4 = 0^64 || 1^64 (the same as X2 for convenience; we’ll avoid accidental dependence by the second triple using a different base).\\n - Let X5 = 1^64 || 0^64 (first half all ones, second half all zeros).\\n - Let X6 = X4 ⊕ X5 = (1^64 || 1^64).\\n\\n The two triples are (X1, X2, X3) and (X4, X5, X6). They give two independent checks of the same affine-structure quantity.\\n\\n- For a generic affine function f(x) = A x ⊕ b over GF(2)^128, we have for any x,y:\\n f(x) ⊕ f(y) ⊕ f(x ⊕ y) = b.\\n Therefore, if f is affine, the 128‑bit value\\n T(x,y) = f(x) ⊕ f(y) ⊕ f(x ⊕ y)\\n is constant and equal to b, for all x,y. So for the two triples, we should observe\\n t1 = f(X1) ⊕ f(X2) ⊕ f(X3) = b,\\n t2 = f(X4) ⊕ f(X5) ⊕ f(X6) = b,\\n hence t1 = t2 with extremely high probability (the only way they could differ is a ceil(2^-128)‑level collision across two independent evaluations).\\n\\n- What you actually do (queries and transcript):\\n - Query 1: input X1 = 0^128; observe Y1 = f(X1).\\n - Query 2: input X2 = 0^64 || 1^64; observe Y2 = f(X2).\\n - Query 3: input X3 = X1 ⊕ X2; observe Y3 = f(X3).\\n - Compute t1 = Y1 ⊕ Y2 ⊕ Y3.\\n\\n - Query 4: input X4 = 0^64 || 1^64; observe Y4 = f(X4).\\n - Query 5: input X5 = 1^64 || 0^64; observe Y5 = f(X5).\\n - Query 6: input X6 = X4 ⊕ X5; observe Y6 = f(X6).\\n - Compute t2 = Y4 ⊕ Y5 ⊕ Y6.\\n\\n- Decision rule after 6 queries:\\n - If t1 = t2 (down to exact bit equality, within machine precision), classify as affine (candidate 3 or 5).\\n - If t1 ≠ t2, classify as non-affine (candidate 1, 2, or 4).\\n\\nNotes:\\n- The probability that a non-affine function yields t1 = t2 for both triples is at most about 2^-128, so this yields a clean separation in practice.\\n- If you want a safer margin, you can repeat the test with another independent pair of triples (costing a few more queries) and require two out of three to agree; with 2000 total budget this is still cheap and provides overwhelming confidence.\\n\\n2) If affine: separate 5 from 3 (robustly)\\n\\n- We are in the affine branch (t1 = t2). Now determine if A = I (i.e., f(x) = x ⊕ b) or not (i.e., f is a nontrivial affine map).\\n- A simple, robust check is to test whether f∘f is the identity on a small, random subset of inputs. For f(x) = A x ⊕ b, one has\\n f(f(x)) = A(Ax ⊕ b) ⊕ b = A^2 x ⊕ A b ⊕ b.\\n In general, unless A^2 = I and A b = b, this will not equal x for most x.\\n\\n- Practical two-input involution tests (two queries suffice per test):\\n - Test 1: Query x = 0^128, get y = f(x). Query z = f(y) and compare z with x.\\n - For case 5 (A = I, f(x) = x ⊕ b with b ≡ K), f(f(0)) = 0, so z = 0 = x.\\n - For most affine cases with A ≠ I, f(f(0)) ≠ 0.\\n - Test 2: If Test 1 passed (z = x), test with another input x' = 1^128 (or any nonzero x) in the same way:\\n - Compute y' = f(x'), z' = f(y'), check whether z' = x'.\\n - Decision after two tests:\\n - If both tests produce f(f(x)) = x for the two chosen x’s, declare 5.\\n - If any test yields f(f(x)) ≠ x for some chosen x, declare 3.\\n\\nNotes and robustness:\\n- It is possible in principle (though with small probability) that some affine maps with A ≠ I and a particular b satisfy f∘f = id for a few special x; to guard against that, you can choose two distinct nonzero inputs (as above) and require both pass; the probability that both pass for A ≠ I is still negligible in GF(2)^128.\\n- If you want even stronger confidence you could test a third input as well, but two such tests already give overwhelming confidence that A ≠ I is unlikely and that you truly have 5 when all tests pass.\\n\\n3) If non-affine: separate 4 from {1, 2}\\n\\n- Now we are in the non-affine branch (cases 1, 2, 4). Use the “factorization by halves” property to pull out 4.\\n\\n- Choose a fixed first-half value a ∈ {0,1}^64 and two distinct second-half values b1 ≠ b2 ∈ {0,1}^64.\\n - Query X = (a, b1) and Y = (a, b2). Observe F(X) and F(Y), each 128 bits.\\n\\n- Compare the first 64 bits of F(X) and F(Y).\\n\\n- Decision rule:\\n - If the first halves of F(X) and F(Y) are identical, declare 4 with high confidence (the first output half in case 4 depends only on the first input half a; varying the second half b does not affect the first output half). The probability that the first halves match by accident for a random 128‑bit permutation (cases 1 or 2) is 2^-64, which is negligible. \\n - If the first halves are different, declare not-4; the remaining possibilities are 1 or 2.\\n\\n- Distinguishing 1 vs 2 after ruling out 4:\\n - This is the tricky part. With only 2000 queries, there is no known information-theoretic guarantee (under standard cryptographic assumptions) that you can distinguish a truly random 128‑bit permutation from AES-128 with an unknown key, because AES is designed to be a pseudorandom permutation indistinguishable from a random permutation with polynomially many queries. Hence, there is no bounded-number, deterministic strategy that, in the worst case, distinguishes 1 from 2 with non-negligible advantage. In practice, any such attempt relies on cryptanalytic assumptions rather than unconditional reasoning.\\n\\n- Practical stance for this subproblem:\\n - If one accepts the standard cryptographic heuristic that AES with an unknown key is indistinguishable from a random permutation for polynomially many queries, then after you have eliminated 4, you should treat the remaining options as essentially indistinguishable within the given query budget. Your best operational choice then is to guess between 1 and 2 (e.g., random guess, or a fixed guess), accepting an impossibility to guarantee correctness better than random guessing. The failure probability would be roughly 1/2 for this last step, as long as you have not observed any distinguishing signature.\\n - If you are allowed to modify the problem (see below), you could make this final distinction provable.\\n\\nSummary of the adaptive query plan and transcript rules\\n\\n- Total queries used for the affine test (Stage A): 6 queries\\n - Q1: X1 = 0^128\\n - Q2: X2 = 0^64 || 1^64\\n - Q3: X3 = X1 ⊕ X2\\n - Q4: X4 = 0^64 || 1^64\\n - Q5: X5 = 1^64 || 0^64\\n - Q6: X6 = X4 ⊕ X5\\n - Transcript check: t1 = f(X1) ⊕ f(X2) ⊕ f(X3); t2 = f(X4) ⊕ f(X5) ⊕ f(X6).\\n - If t1 = t2 → affine branch; else non-affine branch.\\n\\n- If affine (t1 = t2):\\n - Test involution on two inputs:\\n - Q7: X7 = 0^128; observe f(X7) = Y7\\n - Q8: X8 = Y7; observe Z8 = f(X8)\\n - Check whether Z8 = X7 (i.e., f(f(0)) = 0)\\n - Q9: X9 = 1^128; observe Y9; Q10: f(Y9) to get Z10; check whether Z10 = X9\\n - Decision after Q8–Q10:\\n - If both Z8 = X7 and Z10 = X9, declare 5.\\n - If any of these fails, declare 3.\\n\\n- If non-affine (t1 ≠ t2):\\n - Test halves-invariance to pull out 4:\\n - Q11: X11 = (a, b1) with a = 0^64, b1 = 0^64\\n - Q12: X12 = (a, b2) with a = 0^64, b2 = 1^64\\n - Compare first 64 bits of f(X11) and f(X12)\\n - Decision after Q12:\\n - If first halves match, declare 4.\\n - If first halves differ, declare either 1 or 2 (no reliable unconditional method to distinguish them with a fixed small budget; see caveats below).\\n\\n- If you want a concrete final decision between 1 and 2 under this plan, you would need to invoke an unproven cryptographic assumption (PRP indistinguishability) or allow a far larger query budget. The plan above gives a robust, provably correct identification for 3, 4, 5, and a heuristic/PRP-based approach for 1 vs 2.\\n\\nWhy this distinguishes cases 3–5 better than random guessing\\n\\n- Case 4 vs others: The first output half in case 4 depends only on the first input half. The test with a fixed a and two distinct b’s shows that the first halves are equal in 4 with probability exactly 1, whereas for a random 128‑bit permutation (case 1) or AES (case 2) this happens with probability 2^-64. With a single such pair of queries you isolate 4 with overwhelming probability (nearly certainty for 2^-64 error). In the affine branch you don’t even reach this step if the function is affine, so the 4 decision is cleanly separated from 1, 2, and 3 (and is not confused with 5 since 5 is affine).\\n\\n- Case 5 vs 3: Both are affine, but 5 has A = I. The two-invocation test f(f(x)) = x is a robust discriminator: for 5, it holds for all x; for most affine 3 cases (A ≠ I), f(f(x)) ≠ x for most x, and two independent probes already give a very high confidence. This separates 5 from 3 very reliably, while preserving the earlier affine/non-affine separation.\\n\\n- Case 1 and Case 2: With the plan above, you separate 4 from {1,2} using the half-factorization test. After that, distinguishing 1 from 2 cannot be guaranteed with a fixed finite budget in an unconditional way (see the next section). So, while the plan is excellent for 3, 4, 5, it leaves an intrinsic hardness for 1 vs 2 unless you assume standard cryptographic indistinguishability (which is a computational assumption, not an information-theoretic one).\\n\\nInformation-theoretic notes and the 1 vs 2 distinction\\n\\n- Within the given 2000-query budget and with no extra assumptions, there is no known unconditional, information-theoretic procedure that can reliably distinguish a truly random permutation on 128‑bit strings (case 1) from AES-128 with an unknown key applied to a single 128‑bit block (case 2). Both are permutations of the same domain, and AES is designed to be indistinguishable from random in the standard cryptographic sense for polynomial-time adversaries. Without invoking cryptographic hardness assumptions, one cannot guarantee a bounded‑query distinguisher with non-negligible advantage.\\n\\n- If you adopt the standard cryptographic heuristic that AES with an unknown key is a pseudorandom permutation (PRP) indistinguishable from a true random permutation with any polynomially bounded adversary, then there is no bounded-test strategy (in the worst case) that has non-negligible distinguishing advantage between 1 and 2. The advantage would be negligible in the security parameter (128 bits here). Practically, that means: with 2000 queries you should not expect to distinguish 1 from 2 with non-negligible probability; the best you can do is rely on the small statistics you might observe, which are not reliable guarantees.\\n\\n- Therefore, in the present framing, you can claim:\\n - We can reliably separate 3, 4, 5 from each other with a bounded number of queries (6 for the affine check, plus a couple of extra tests for 5 vs 3, plus the 4-vs-1/2 test described).\\n - We cannot, in general, guarantee distinguishing 1 from 2 with a bounded, unconditional strategy. The most you can do is rely on cryptographic assumptions (PRP indistinguishability) to claim that any such distinction has only negligible advantage.\\n\\n- How to modify the problem to make 1 vs 2 distinguishable with bounded queries:\\n - Remove the cryptographic indistinguishability ambiguity by giving the solver an explicit oracle for a second evaluation of f under a known, new key (i.e., allow reinitialization of the box to a fresh AES instance with a new random key for a second phase). With two unrelated AES instances, you could try to detect the difference between a fully random permutation and AES under a control key schedule. Or,\\n - Fix the box to be a single random permutation versus a fixed but unknown‑key block cipher, and require that the box cannot simulate the PRP behavior across many inputs in a way indistinguishable from the uniform permutation. Either change yields a setting where you can derive a provable distinguishing strategy (or at least a bounded, provable advantage).\\n\\nMinimum number of queries and boundedness\\n\\n- The affine test (Stage 0 with 6 queries) plus the involution test (2–4 additional queries in the affine branch) plus the halves test for non-affine (2–3 queries) gives you a practical, concrete protocol that deterministically identifies 3, 4, and 5 with high probability, using on the order of 6–12 queries in total in typical runs.\\n\\n- In particular, you can guarantee:\\n - Case 5 (f(x) = x ⊕ K) vs Case 3 (affine with A ≠ I): high confidence via f∘f tests.\\n - Case 3 vs Case 4 vs Case 1: clear separation by affine test and then by the halves factorization test.\\n - Case 1 vs Case 2: not guaranteed with a fixed, small bound; relies on standard cryptographic assumptions (see above).\\n\\n- If you want an explicit lower bound statement: No strictly bounded, unconditional strategy can guarantee distinguishing 1 from 2 with non-negligible probability in this setting, because both functions are (to within the natural model) indistinguishable by polynomially many queries. The only way to guarantee a distinction would be to impose a new assumption or change the problem (as described above).\\n\\nPutting it together as a concrete protocol\\n\\n- Phase 1 (6 queries): affine test\\n - Query X1 = 0^128, X2 = 0^64||1^64, X3 = X1⊕X2\\n - Query X4 = 0^64||1^64, X5 = 1^64||0^64, X6 = X4⊕X5\\n - Compute t1 = f(X1) ⊕ f(X2) ⊕ f(X3), t2 = f(X4) ⊕ f(X5) ⊕ f(X6).\\n - If t1 ≠ t2, non-affine branch; if t1 = t2, affine branch.\\n\\n- Phase 2a (affine branch): separate 5 from 3\\n - Query X7 = 0^128; observe Y7 = f(X7)\\n - Query X8 = Y7; observe Z8 = f(X8)\\n - If Z8 = X7, test a second input X9 = 1^128; Query X10 = f(X9); Query X11 = f(X10); If X or both pass (Z8 = X7 and Z11 = X9), declare 5; else declare 3.\\n - (Two tests are enough in practice to drive the error probability to negligible levels.)\\n\\n- Phase 2b (non-affine branch): separate 4 from {1,2}\\n - Fixed a = 0^64, b1 = 0^64, b2 = 1^64\\n - Query X12 = (a,b1), X13 = (a,b2)\\n - If the first 64 bits of f(X12) and f(X13) are equal, declare 4; else proceed to Phase 2c.\\n - Phase 2c to separate 1 vs 2 is not guaranteed unconditionally with bounded queries. You either accept a negligible advantage-based separation under PRP indistinguishability (i.e., no practical advantage) or you modify the problem as suggested above.\\n\\nWhy this strategy satisfies the problem’s requirements\\n\\n- It gives a concrete, adaptive plan with explicit inputs for each query, and explicit decision rules on all possible transcripts you might observe (up to the probabilistic caveat for the 1 vs 2 distinction).\\n- It provides a rigorous justification for why the affine test separates 3/5 from 1/2/4 with overwhelming probability, and why the half-by-half test separates 4 from the others in the non-affine branch.\\n- It gives a principled argument for why, in the 1 vs 2 subproblem, you cannot guarantee a bounded success probability without additional cryptographic assumptions (hence the discussion about indistinguishability and possible problem modifications).\\n\\nIf you want a completely foolproof identification of all five cases (including a provable 1 vs 2 distinction), here are two natural modifications you could consider\\n\\n- Change the problem to guarantee that the box’s 2 (AES) instance cannot be made indistinguishable from a random permutation under the given query budget (e.g., by providing side information about the key schedule, or requiring multiple keys and independent encryptions). Then you could design a polynomial-time distinguisher with non-negligible advantage; you could then separate 1 and 2 with a bounded query budget.\\n\\n- Alternatively, require the box to be reset with a fresh independently chosen permutation for each batch of queries (or to re-keyAES after every block). In that setting, you could exploit changes in mapping across batches to distinguish 1 (static random permutation) from 2 (AES under a fixed key), with guaranteed separation in a bounded number of queries.\\n\\nBottom line\\n\\n- A concrete, practical strategy exists to reliably distinguish 3, 4, and 5 within a modest, bounded number of queries (6 for the affine test, plus a few extra tests). Distinguishing 1 from 2 with a small, fixed budget cannot be guaranteed unconditionally; it hinges on standard cryptographic assumptions about AES being indistinguishable from a random permutation. If you’re willing to accept such an assumption, Phase 2 between 1 and 2 becomes a routine PRP indistinguishability test; if not, you must either increase the budget dramatically or modify the problem as described.\", 'The task is to design an adaptive querying strategy to distinguish between five types of 128-bit functions with a budget of 2,000 queries, using only paper reasoning.\\n\\nLet\\'s first analyze the key properties of each function type:\\n\\n1. **Random Permutation (RP):** A truly random, bijective mapping. No discernible structure or pattern for a small number of queries.\\n2. **AES-128 (ECB mode) (AES):** A pseudorandom permutation (PRP). It\\'s computationally indistinguishable from a random permutation for any adversary with limited computational resources and a reasonable number of queries.\\n3. **Affine function \\\\(f(x)=A x \\\\oplus b\\\\):** A linear transformation \\\\(Ax\\\\) over \\\\(\\\\mathbb{F}_2^{128}\\\\) (where \\\\(A\\\\) is an invertible \\\\(128\\\\times128\\\\) binary matrix) followed by an XOR with a constant \\\\(b\\\\).\\n * **Key Property:** For any inputs \\\\(x_1, x_2\\\\), \\\\(f(x_1) \\\\oplus f(x_2) = A(x_1 \\\\oplus x_2)\\\\). This implies that if \\\\(x_1 \\\\oplus x_2 = x_3 \\\\oplus x_4\\\\), then \\\\(f(x_1) \\\\oplus f(x_2) = f(x_3) \\\\oplus f(x_4)\\\\). More specifically, for a fixed \\\\(\\\\Delta \\\\ne 0\\\\), the output difference \\\\(f(x \\\\oplus \\\\Delta) \\\\oplus f(x)\\\\) is constant for all \\\\(x\\\\).\\n4. **Split Random Permutation \\\\(f(x)=g(x_L)\\\\,\\\\|\\\\,h(x_R)\\\\):** The input \\\\(x\\\\) is split into a 64-bit left part \\\\(x_L\\\\) and a 64-bit right part \\\\(x_R\\\\). The output is formed by concatenating \\\\(g(x_L)\\\\) and \\\\(h(x_R)\\\\), where \\\\(g\\\\) and \\\\(h\\\\) are independent random permutations on 64-bit strings.\\n * **Key Property:** If \\\\(x_L\\\\) is held constant, then the left 64 bits of the output \\\\(g(x_L)\\\\) remain constant, regardless of changes in \\\\(x_R\\\\). Similarly, if \\\\(x_R\\\\) is held constant, the right 64 bits of the output \\\\(h(x_R)\\\\) remain constant.\\n5. **XOR with a fixed key \\\\(f(x)=x\\\\oplus K\\\\):** A very simple affine function where \\\\(A\\\\) is the identity matrix.\\n * **Key Property:** For any inputs \\\\(x_1, x_2\\\\), \\\\(f(x_1) \\\\oplus f(x_2) = (x_1 \\\\oplus K) \\\\oplus (x_2 \\\\oplus K) = x_1 \\\\oplus x_2\\\\). The output difference is always equal to the input difference.\\n\\n**Strategy Overview:**\\n\\nThe strategy will involve a sequence of adaptive tests, moving from the most specific and easily detectable properties (XOR) to more general ones (Affine, Split RP). If none of these specific patterns are detected, the function is classified as either AES or Random Permutation, which are considered indistinguishable under the given constraints. Each test is designed to exploit a unique structural property that is highly unlikely to occur by chance in other function types (especially RP or AES).\\n\\n**Notation:**\\n* `Q(x)`: Submit input `x` and observe the output.\\n* `y[L]`: The first 64 bits of a 128-bit value `y`.\\n* `y[R]`: The last 64 bits of a 128-bit value `y`.\\n\\n---\\n\\n**Detailed Adaptive Querying Strategy:**\\n\\nWe will use a total of **9 queries** to identify Cases 3, 4, or 5 with very high probability. If none of these are identified, we classify it as Case 1 or 2.\\n\\n**Phase 1: Test for Case 5 (XOR with a fixed key)**\\nThis is the strongest structural property.\\n1. **Query 1:** Set \\\\(x_1 = 0^{128}\\\\) (all zeros). Query \\\\(Q(x_1)\\\\), observe \\\\(y_1\\\\).\\n2. **Query 2:** Set \\\\(x_2 = 0^{127}1\\\\) (value 1). Query \\\\(Q(x_2)\\\\), observe \\\\(y_2\\\\).\\n3. **Query 3:** Set \\\\(x_3 = 0^{126}10\\\\) (value 2). Query \\\\(Q(x_3)\\\\), observe \\\\(y_3\\\\).\\n\\n* **Decision Rule for XOR:**\\n If \\\\((y_2 \\\\oplus y_1 = x_2 \\\\oplus x_1)\\\\) AND \\\\((y_3 \\\\oplus y_1 = x_3 \\\\oplus x_1)\\\\):\\n **Declare Case 5 (XOR)**. Stop.\\n* **Justification:** For \\\\(f(x)=x \\\\oplus K\\\\), these conditions must hold (e.g., \\\\(f(1) \\\\oplus f(0) = (1 \\\\oplus K) \\\\oplus (0 \\\\oplus K) = 1 \\\\oplus 0 = 1\\\\)). For a random permutation, AES, affine function with \\\\(A \\\\ne I\\\\), or split RP, the probability of satisfying these two conditions is approximately \\\\((1/2^{128}) \\\\times (1/2^{128}) = 1/2^{256}\\\\). This is an astronomically low probability of false positive.\\n\\n**Phase 2: Test for Case 3 (Affine function)**\\nThis phase is executed only if Case 5 was NOT identified in Phase 1.\\n4. **Query 4:** Choose a fixed difference \\\\(\\\\Delta = 0^{125}100\\\\) (value 4). This value is distinct from \\\\(x_1, x_2, x_3\\\\). Set \\\\(x_4 = x_1 \\\\oplus \\\\Delta = 0 \\\\oplus 4 = 4\\\\). Query \\\\(Q(x_4)\\\\), observe \\\\(y_4\\\\).\\n5. **Query 5:** Set \\\\(x_5 = x_2 \\\\oplus \\\\Delta = 1 \\\\oplus 4 = 5\\\\). Query \\\\(Q(x_5)\\\\), observe \\\\(y_5\\\\).\\n6. **Query 6:** Set \\\\(x_6 = x_3 \\\\oplus \\\\Delta = 2 \\\\oplus 4 = 6\\\\). Query \\\\(Q(x_6)\\\\), observe \\\\(y_6\\\\).\\n (All inputs \\\\(x_1 \\\\dots x_6\\\\) are distinct: 0, 1, 2, 4, 5, 6).\\n\\n* **Decision Rule for Affine:**\\n Let \\\\(D_0 = y_4 \\\\oplus y_1\\\\). (This is the candidate value for \\\\(A\\\\Delta\\\\)).\\n If \\\\((y_5 \\\\oplus y_2 = D_0)\\\\) AND \\\\((y_6 \\\\oplus y_3 = D_0)\\\\):\\n **Declare Case 3 (Affine)**. Stop.\\n* **Justification:** For \\\\(f(x)=Ax \\\\oplus b\\\\), the value \\\\(f(x \\\\oplus \\\\Delta) \\\\oplus f(x)\\\\) must be constant for a fixed \\\\(\\\\Delta\\\\) (it equals \\\\(A\\\\Delta\\\\)). So, \\\\(y_4 \\\\oplus y_1\\\\) must equal \\\\(y_5 \\\\oplus y_2\\\\), which must equal \\\\(y_6 \\\\oplus y_3\\\\). The probability of these two equalities holding by chance for a random permutation, AES, or split RP is approximately \\\\((1/2^{128}) \\\\times (1/2^{128}) = 1/2^{256}\\\\).\\n\\n**Phase 3: Test for Case 4 (Split Random Permutation)**\\nThis phase is executed only if Case 5 and Case 3 were NOT identified.\\n7. **Query 7:** Define \\\\(\\\\Delta_L = (1 \\\\ll 127)\\\\), which is the most significant bit of the left 64 bits set to 1. Set \\\\(x_7 = x_1 \\\\oplus \\\\Delta_L = \\\\Delta_L\\\\). Query \\\\(Q(x_7)\\\\), observe \\\\(y_7\\\\).\\n8. **Query 8:** Define \\\\(\\\\Delta_R = (1 \\\\ll 63)\\\\), which is the most significant bit of the right 64 bits set to 1. Set \\\\(x_8 = x_1 \\\\oplus \\\\Delta_R = \\\\Delta_R\\\\). Query \\\\(Q(x_8)\\\\), observe \\\\(y_8\\\\).\\n9. **Query 9:** Set \\\\(x_9 = x_1 \\\\oplus \\\\Delta_L \\\\oplus \\\\Delta_R = \\\\Delta_L \\\\oplus \\\\Delta_R\\\\). Query \\\\(Q(x_9)\\\\), observe \\\\(y_9\\\\).\\n (All inputs \\\\(x_1 \\\\dots x_9\\\\) are distinct: 0, 1, 2, 4, 5, 6, \\\\(\\\\Delta_L\\\\), \\\\(\\\\Delta_R\\\\), \\\\(\\\\Delta_L \\\\oplus \\\\Delta_R\\\\)).\\n\\n* **Decision Rule for Split RP:**\\n If \\\\((y_7[R] = y_1[R])\\\\) AND \\\\((y_8[L] = y_1[L])\\\\) AND \\\\((y_9[L] = y_7[L])\\\\) AND \\\\((y_9[R] = y_8[R])\\\\):\\n **Declare Case 4 (Split RP)**. Stop.\\n* **Justification:** For \\\\(f(x)=g(x_L)\\\\,\\\\|\\\\,h(x_R)\\\\):\\n * \\\\(x_R(x_7) = x_R(\\\\Delta_L) = 0\\\\), and \\\\(x_R(x_1) = x_R(0) = 0\\\\). So \\\\(y_7[R] = h(0)\\\\) and \\\\(y_1[R] = h(0)\\\\). They must be equal. (Prob for RP/AES/Affine: \\\\(1/2^{64}\\\\)).\\n * \\\\(x_L(x_8) = x_L(\\\\Delta_R) = 0\\\\), and \\\\(x_L(x_1) = x_L(0) = 0\\\\). So \\\\(y_8[L] = g(0)\\\\) and \\\\(y_1[L] = g(0)\\\\). They must be equal. (Prob for RP/AES/Affine: \\\\(1/2^{64}\\\\)).\\n * \\\\(x_L(x_9) = x_L(\\\\Delta_L \\\\oplus \\\\Delta_R) = x_L(\\\\Delta_L)\\\\). So \\\\(y_9[L] = g(x_L(\\\\Delta_L)) = y_7[L]\\\\). This condition holds with probability 1 for Split RP. For RP/AES/Affine, \\\\(y_9[L]\\\\) would be a new random 64-bit value, so probability of match is \\\\(1/2^{64}\\\\).\\n * \\\\(x_R(x_9) = x_R(\\\\Delta_L \\\\oplus \\\\Delta_R) = x_R(\\\\Delta_R)\\\\). So \\\\(y_9[R] = h(x_R(\\\\Delta_R)) = y_8[R]\\\\). This condition also holds with probability 1 for Split RP. For RP/AES/Affine, \\\\(y_9[R]\\\\) would be a new random 64-bit value, so probability of match is \\\\(1/2^{64}\\\\).\\n The combined probability of all four conditions occurring by chance for RP/AES/Affine is approximately \\\\((1/2^{64})^4 = 1/2^{256}\\\\).\\n\\n**Phase 4: Indistinguishable Cases (RP or AES-128)**\\nThis phase is executed only if none of the specific patterns were identified in Phases 1-3.\\n\\n* **Decision Rule for RP/AES:**\\n If none of the above conditions are met after 9 queries:\\n **Declare Cases 1 or 2 (Indistinguishable: Random Permutation or AES-128)**. Stop.\\n* **Justification:**\\n * **Computational Indistinguishability:** AES is designed to be a strong pseudorandom permutation (PRP). For an adversary with \"paper reasoning\" (i.e., no computational resources to perform complex statistical analyses) and a limited number of queries (2,000 queries is very small compared to the \\\\(2^{128}\\\\) domain size), AES-128 is computationally indistinguishable from a truly random permutation. Any simple statistical test that could be performed manually (e.g., checking for immediate collisions or very short cycles) would fail to distinguish them with 2,000 queries due to the vast domain.\\n * **Information-Theoretic Indistinguishability:** There is no known structural property of AES that would manifest within 2,000 queries (or even a much larger number, like \\\\(2^{64}\\\\)) that is simple enough to be detected by \"paper reasoning\" and not also be present in a random permutation with high probability, or ruled out by previous tests. The specific structural properties of AES (e.g., S-boxes, mix columns, key schedule) are designed to diffuse input changes rapidly, preventing simple patterns from emerging.\\n\\n---\\n\\n**Summary of Queries and Success Probability:**\\n\\n* **Minimum Queries:** 3 (if XOR), 6 (if Affine), or 9 (if Split RP or RP/AES).\\n* **Maximum Queries Used:** 9. The strategy is well within the 2,000 query budget.\\n* **Success Probability:**\\n * For XOR, Affine, and Split RP functions, the probability of correctly identifying them is extremely high (error probability of roughly \\\\(1/2^{256}\\\\) for each, due to false positives from other types).\\n * For Random Permutation and AES-128, the strategy groups them as \"indistinguishable\". This maximizes success probability because, given the constraints (2,000 queries, paper reasoning), there\\'s no reliable way to tell them apart. If a single distinct answer is required for all five, then the success probability for these two cases would be very low (e.g., 50% if forced to guess), as there are no distinguishing features discoverable under the given conditions.\\n\\n---\\n\\n**Modifications to make AES/RP distinguishable:**\\n\\nTo make AES-128 and a uniformly random permutation distinguishable with a high success probability, one would need to alter the problem constraints significantly:\\n\\n1. **Increased Query Budget:** A much larger query budget, ideally in the order of \\\\(2^{64}\\\\) or more, would allow an adversary to perform statistical tests (like chi-squared tests on output distributions, birthday attacks on internal states, or more advanced cryptanalytic techniques) that could detect non-randomness in AES.\\n2. **Computational Resources:** Allowing computational resources would enable an adversary to process and analyze the outputs of thousands or millions of queries, looking for subtle statistical biases or patterns that are characteristic of AES but not of a truly random function. \"Paper reasoning\" explicitly rules out such analysis.\\n3. **Known Plaintext/Ciphertext Pairs for AES:** If the adversary had access to known plaintext/ciphertext pairs for the specific AES key, they could compare them against the black box\\'s output, thus confirming AES.\\n4. **Side-Channel Information:** Access to side-channel information (e.g., timing, power consumption, electromagnetic radiation) during the black box\\'s computation of \\\\(f(x)\\\\) could easily distinguish AES from a hypothetical \"truly random\" hardware implementation.', '### Executive Summary\\nTo distinguish between the five cases with the highest possible success probability, only **4 adaptive queries** are sufficient. This strategy exploits the specific algebraic and structural properties of each function to rule out candidates efficiently.\\n\\nThe identification follows a strict hierarchy:\\n1. **Case 5 (XOR Mask):** Detected via constant differential properties.\\n2. **Case 4 (Split Permutation):** Detected via partial independence (changing half the input does not change the other half of the output).\\n3. **Case 3 (Affine):** Detected via additive relationships (XOR sums of inputs equal XOR sums of outputs).\\n4. **Cases 1 & 2 (Random Perm / AES):** These are information-theoretically indistinguishable within the given budget.\\n\\n---\\n\\n### Detailed Adaptive Querying Strategy\\n\\n#### Phase 1: Initialization\\nWe begin by defining four basis vectors to probe the function\\'s linearity and bit-dependency.\\n1. **Query 1 ($x_0$):** Submit `00...00` (128 zeros). Receive $y_0$.\\n2. **Query 2 ($x_1$):** Submit `10...00` (Bit 127 set; Upper Half). Receive $y_1$.\\n3. **Query 3 ($x_2$):** Submit `00...01` (Bit 0 set; Lower Half). Receive $y_2$.\\n\\nAt this point, we have evaluated the function at the origin and at two orthogonal unit vectors.\\n\\n#### Phase 2: Sequential Decision Rules\\n\\n**Step 1: Check for Case 5 (XOR Mask)**\\nA function in Case 5 satisfies $f(x) = x \\\\oplus K$. Thus, $f(x) \\\\oplus x$ must equal the constant vector $K$.\\n* **Compute Candidate Keys:**\\n * $K_0 = y_0 \\\\oplus 0 = y_0$\\n * $K_1 = y_1 \\\\oplus x_1$\\n * $K_2 = y_2 \\\\oplus x_2$\\n* **Decision Rule:**\\n * If **$K_0 = K_1 = K_2$**, identify **Case 5**. Terminate.\\n * Otherwise, proceed to Step 2.\\n * *Reasoning:* In Case 5, this equality holds with probability 1. In all other cases, the probability of this happening for 3 points is roughly $2^{-384}$.\\n\\n**Step 2: Check for Case 4 (Split Permutation)**\\nA function in Case 4 is separable: $f(x_L, x_R) = (\\\\pi_1(x_L), \\\\pi_2(x_R))$.\\n* **Property:** Changing the Upper Input ($x_L$) should **not** affect the Lower Output ($Y_R$). Conversely, changing the Lower Input ($x_R$) should **not** affect the Upper Output ($Y_L$).\\n* **Action:** Compare the halves of the received outputs.\\n 1. Extract the Lower 64 bits of $y_1$ and $y_0$.\\n 2. Extract the Upper 64 bits of $y_2$ and $y_0$.\\n* **Decision Rule:**\\n * If (Lower half of $y_1$ == Lower half of $y_0$) **AND** (Upper half of $y_2$ == Upper half of $y_0$), identify **Case 4**. Terminate.\\n * Otherwise, proceed to Step 3.\\n * *Reasoning:* This specific structural independence holds for Case 4. It fails for random or fully mixed functions with probability $1 - 2^{-64}$.\\n\\n**Step 3: Check for Case 3 (Affine Transformation)**\\nIf the first two tests fail, we check for linearity. Case 3 functions satisfy $f(A \\\\oplus B) = f(A) \\\\oplus f(B) \\\\oplus f(0)$.\\n* **Action:**\\n 1. Compute the target XOR sum: $Target = y_0 \\\\oplus y_1 \\\\oplus y_2$.\\n 2. **Query 4 ($x_3$):** Submit $x_1 \\\\oplus x_2$ (bits 127 and 0 set). Receive $y_3$.\\n* **Decision Rule:**\\n * If **$y_3 = Target$**, identify **Case 3**. Terminate.\\n * Otherwise, proceed to Final Assessment.\\n * *Reasoning:* This check verifies the affine homomorphism property. While Case 5 also satisfies this, it was ruled out in Step 1.\\n\\n**Final Assessment: Case 1 or 2**\\nIf all structural checks fail, the function lacks the algebraic structure of 3, 4, or 5.\\n* **Identification:** **Case 1 (Random Permutation) or Case 2 (AES-128).**\\n* *Reasoning:* Both are permutations with no detectable bias under this query budget.\\n\\n---\\n\\n### Justification\\n\\n1. **Case 5 (Linear/XOR):** Defined by a constant differential. Any deviation in $f(x) \\\\oplus x$ rules it out.\\n2. **Case 4 (Separable):** Defined by independent sub-spaces. Testing coordinate independence is a definitive structural signature.\\n3. **Case 3 (Affine):** Defined by linear superposition. The XOR-additivity check $f(x \\\\oplus y) \\\\oplus f(x) \\\\oplus f(y) \\\\oplus f(0) = 0$ is a rigorous mathematical test for affine maps.\\n4. **Cases 1 vs 2:** Distinguishability relies on finding statistical deviations from randomness. AES-128 is a Pseudorandom Permutation (PRP); its outputs are computationally indistinguishable from a truly Random Permutation. With a budget of 2,000 queries (significantly below the birthday bound of $2^{64}$), no information-theoretic distinguisher exists.\\n\\n---\\n\\n### Indistinguishability of Cases 1 and 2\\n\\n**Why they are indistinguishable:**\\nUnder the given constraints, Case 1 and Case 2 are information-theoretically indistinguishable. A secure block cipher like AES is designed specifically to mimic a Random Permutation. With $N=2000$ queries, the statistical distance between the output distribution of AES and a Uniform Random Permutation is vanishingly small (advantage $\\\\approx N^2/2^{128}$).\\n\\n**Proposed Problem Modifications to Enable Distinction:**\\nTo make Case 1 distinguishable from Case 2, one could:\\n1. **Increase Query Budget Exponentially:** Raising the query limit to $\\\\ge 2^{64}$ would allow the observation of collisions or statistical biases inherent in the construction, though this remains computationally difficult.\\n2. **Alter Case 1 (Null Hypothesis):** Replace \"Random Permutation\" with **\"Random Function\"**. A Random Function allows collisions ($f(x) = f(y)$ for $x \\\\neq y$), while AES (Case 2) remains a permutation. Checking for output collisions would instantly identify Case 1.\\n3. **Alter Case 2 (Weak Cipher):** Specify AES with a **weak key** (e.g., $K=0$) or a known variation with a known distinguisher (e.g., a specific linear trail), allowing manual verification.']\n" ] } ], "source": [ "# So where are we?\n", "\n", "print(competitors)\n", "print(answers)\n" ] }, { "cell_type": "code", "execution_count": 56, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Competitor: gpt-5-nano\n", "\n", "Below is a concrete, adaptive strategy that (i) uses a bounded number of 128‑bit queries, (ii) works for all five possibilities with high probability, and (iii) makes explicit the transcript-based decision rules. I also include a careful discussion of what can and cannot be guaranteed with the given budget, and how you could modify the problem if you want a provable distinction in all five cases.\n", "\n", "High-level plan (what we try to separate and why)\n", "\n", "- A quick affine/linear test lets us separate the “affine” family f(x) = A x ⊕ b from all the genuinely non‑affine possibilities (cases 1, 2, 4). This immediately distinguishes 5 (A = I, b = K) from all non‑affine cases with very high probability, and separates 3 (A arbitrary invertible) from 5.\n", "\n", "- If we flag affine and the test is consistent with A = I (the XOR-with-a-constant family), we can separate case 5 from the rest of the affine family using a small extra test (involution style): for case 5, f∘f = id; for generic affine (case 3 with A ≠ I), f∘f is not the identity for almost all inputs (and we can detect this with a couple of probes). This gives a robust way to distinguish 5 from 3, while still keeping error probability negligible.\n", "\n", "- If we flag non-affine (i.e., not in affine form), we can separate case 4 from cases 1 and 2 using a simple “factorization by halves” observation: in case 4, the first output half depends only on the first input half, and the second output half depends only on the second input half (g and h are independent 64‑bit permutations). In contrast, a random 128‑bit permutation (case 1) and AES in ECB (case 2) do not factorize this way. With a single carefully chosen pair of queries having the same first input half but different second halves, the first output half should be identical for 4 but not for 1 or 2 with overwhelming probability (2^-64 type small error). This lets us separate 4 from {1,2} with high confidence.\n", "\n", "- Distinguishing 1 vs 2 (uniform random permutation vs AES with an unknown key) cannot be guaranteed to succeed with a bounded, small query budget under standard cryptographic indistinguishability assumptions; both look like random permutations on the 128‑bit domain to any polynomially bounded test. I flag this explicitly and explain how you could modify the task if you want a provable separation in all five cases.\n", "\n", "Now the detailed strategy\n", "\n", "1) Meet-the-affine test (to pull case 3, 5 apart from 1, 2, 4)\n", "\n", "- Query preparation (6 inputs use, two independent triple tests to check affine structure):\n", " - Let X1 = 0^128 (all zero 128 bits).\n", " - Let X2 = 0^64 || 1^64 (first 64 bits zero, last 64 bits all ones).\n", " - Let X3 = X1 ⊕ X2 = 0^64 || 1^64 (note X3 ≠ X1, X3 ≠ X2).\n", "\n", " - Let X4 = 0^64 || 1^64 (the same as X2 for convenience; we’ll avoid accidental dependence by the second triple using a different base).\n", " - Let X5 = 1^64 || 0^64 (first half all ones, second half all zeros).\n", " - Let X6 = X4 ⊕ X5 = (1^64 || 1^64).\n", "\n", " The two triples are (X1, X2, X3) and (X4, X5, X6). They give two independent checks of the same affine-structure quantity.\n", "\n", "- For a generic affine function f(x) = A x ⊕ b over GF(2)^128, we have for any x,y:\n", " f(x) ⊕ f(y) ⊕ f(x ⊕ y) = b.\n", " Therefore, if f is affine, the 128‑bit value\n", " T(x,y) = f(x) ⊕ f(y) ⊕ f(x ⊕ y)\n", " is constant and equal to b, for all x,y. So for the two triples, we should observe\n", " t1 = f(X1) ⊕ f(X2) ⊕ f(X3) = b,\n", " t2 = f(X4) ⊕ f(X5) ⊕ f(X6) = b,\n", " hence t1 = t2 with extremely high probability (the only way they could differ is a ceil(2^-128)‑level collision across two independent evaluations).\n", "\n", "- What you actually do (queries and transcript):\n", " - Query 1: input X1 = 0^128; observe Y1 = f(X1).\n", " - Query 2: input X2 = 0^64 || 1^64; observe Y2 = f(X2).\n", " - Query 3: input X3 = X1 ⊕ X2; observe Y3 = f(X3).\n", " - Compute t1 = Y1 ⊕ Y2 ⊕ Y3.\n", "\n", " - Query 4: input X4 = 0^64 || 1^64; observe Y4 = f(X4).\n", " - Query 5: input X5 = 1^64 || 0^64; observe Y5 = f(X5).\n", " - Query 6: input X6 = X4 ⊕ X5; observe Y6 = f(X6).\n", " - Compute t2 = Y4 ⊕ Y5 ⊕ Y6.\n", "\n", "- Decision rule after 6 queries:\n", " - If t1 = t2 (down to exact bit equality, within machine precision), classify as affine (candidate 3 or 5).\n", " - If t1 ≠ t2, classify as non-affine (candidate 1, 2, or 4).\n", "\n", "Notes:\n", "- The probability that a non-affine function yields t1 = t2 for both triples is at most about 2^-128, so this yields a clean separation in practice.\n", "- If you want a safer margin, you can repeat the test with another independent pair of triples (costing a few more queries) and require two out of three to agree; with 2000 total budget this is still cheap and provides overwhelming confidence.\n", "\n", "2) If affine: separate 5 from 3 (robustly)\n", "\n", "- We are in the affine branch (t1 = t2). Now determine if A = I (i.e., f(x) = x ⊕ b) or not (i.e., f is a nontrivial affine map).\n", "- A simple, robust check is to test whether f∘f is the identity on a small, random subset of inputs. For f(x) = A x ⊕ b, one has\n", " f(f(x)) = A(Ax ⊕ b) ⊕ b = A^2 x ⊕ A b ⊕ b.\n", " In general, unless A^2 = I and A b = b, this will not equal x for most x.\n", "\n", "- Practical two-input involution tests (two queries suffice per test):\n", " - Test 1: Query x = 0^128, get y = f(x). Query z = f(y) and compare z with x.\n", " - For case 5 (A = I, f(x) = x ⊕ b with b ≡ K), f(f(0)) = 0, so z = 0 = x.\n", " - For most affine cases with A ≠ I, f(f(0)) ≠ 0.\n", " - Test 2: If Test 1 passed (z = x), test with another input x' = 1^128 (or any nonzero x) in the same way:\n", " - Compute y' = f(x'), z' = f(y'), check whether z' = x'.\n", " - Decision after two tests:\n", " - If both tests produce f(f(x)) = x for the two chosen x’s, declare 5.\n", " - If any test yields f(f(x)) ≠ x for some chosen x, declare 3.\n", "\n", "Notes and robustness:\n", "- It is possible in principle (though with small probability) that some affine maps with A ≠ I and a particular b satisfy f∘f = id for a few special x; to guard against that, you can choose two distinct nonzero inputs (as above) and require both pass; the probability that both pass for A ≠ I is still negligible in GF(2)^128.\n", "- If you want even stronger confidence you could test a third input as well, but two such tests already give overwhelming confidence that A ≠ I is unlikely and that you truly have 5 when all tests pass.\n", "\n", "3) If non-affine: separate 4 from {1, 2}\n", "\n", "- Now we are in the non-affine branch (cases 1, 2, 4). Use the “factorization by halves” property to pull out 4.\n", "\n", "- Choose a fixed first-half value a ∈ {0,1}^64 and two distinct second-half values b1 ≠ b2 ∈ {0,1}^64.\n", " - Query X = (a, b1) and Y = (a, b2). Observe F(X) and F(Y), each 128 bits.\n", "\n", "- Compare the first 64 bits of F(X) and F(Y).\n", "\n", "- Decision rule:\n", " - If the first halves of F(X) and F(Y) are identical, declare 4 with high confidence (the first output half in case 4 depends only on the first input half a; varying the second half b does not affect the first output half). The probability that the first halves match by accident for a random 128‑bit permutation (cases 1 or 2) is 2^-64, which is negligible. \n", " - If the first halves are different, declare not-4; the remaining possibilities are 1 or 2.\n", "\n", "- Distinguishing 1 vs 2 after ruling out 4:\n", " - This is the tricky part. With only 2000 queries, there is no known information-theoretic guarantee (under standard cryptographic assumptions) that you can distinguish a truly random 128‑bit permutation from AES-128 with an unknown key, because AES is designed to be a pseudorandom permutation indistinguishable from a random permutation with polynomially many queries. Hence, there is no bounded-number, deterministic strategy that, in the worst case, distinguishes 1 from 2 with non-negligible advantage. In practice, any such attempt relies on cryptanalytic assumptions rather than unconditional reasoning.\n", "\n", "- Practical stance for this subproblem:\n", " - If one accepts the standard cryptographic heuristic that AES with an unknown key is indistinguishable from a random permutation for polynomially many queries, then after you have eliminated 4, you should treat the remaining options as essentially indistinguishable within the given query budget. Your best operational choice then is to guess between 1 and 2 (e.g., random guess, or a fixed guess), accepting an impossibility to guarantee correctness better than random guessing. The failure probability would be roughly 1/2 for this last step, as long as you have not observed any distinguishing signature.\n", " - If you are allowed to modify the problem (see below), you could make this final distinction provable.\n", "\n", "Summary of the adaptive query plan and transcript rules\n", "\n", "- Total queries used for the affine test (Stage A): 6 queries\n", " - Q1: X1 = 0^128\n", " - Q2: X2 = 0^64 || 1^64\n", " - Q3: X3 = X1 ⊕ X2\n", " - Q4: X4 = 0^64 || 1^64\n", " - Q5: X5 = 1^64 || 0^64\n", " - Q6: X6 = X4 ⊕ X5\n", " - Transcript check: t1 = f(X1) ⊕ f(X2) ⊕ f(X3); t2 = f(X4) ⊕ f(X5) ⊕ f(X6).\n", " - If t1 = t2 → affine branch; else non-affine branch.\n", "\n", "- If affine (t1 = t2):\n", " - Test involution on two inputs:\n", " - Q7: X7 = 0^128; observe f(X7) = Y7\n", " - Q8: X8 = Y7; observe Z8 = f(X8)\n", " - Check whether Z8 = X7 (i.e., f(f(0)) = 0)\n", " - Q9: X9 = 1^128; observe Y9; Q10: f(Y9) to get Z10; check whether Z10 = X9\n", " - Decision after Q8–Q10:\n", " - If both Z8 = X7 and Z10 = X9, declare 5.\n", " - If any of these fails, declare 3.\n", "\n", "- If non-affine (t1 ≠ t2):\n", " - Test halves-invariance to pull out 4:\n", " - Q11: X11 = (a, b1) with a = 0^64, b1 = 0^64\n", " - Q12: X12 = (a, b2) with a = 0^64, b2 = 1^64\n", " - Compare first 64 bits of f(X11) and f(X12)\n", " - Decision after Q12:\n", " - If first halves match, declare 4.\n", " - If first halves differ, declare either 1 or 2 (no reliable unconditional method to distinguish them with a fixed small budget; see caveats below).\n", "\n", "- If you want a concrete final decision between 1 and 2 under this plan, you would need to invoke an unproven cryptographic assumption (PRP indistinguishability) or allow a far larger query budget. The plan above gives a robust, provably correct identification for 3, 4, 5, and a heuristic/PRP-based approach for 1 vs 2.\n", "\n", "Why this distinguishes cases 3–5 better than random guessing\n", "\n", "- Case 4 vs others: The first output half in case 4 depends only on the first input half. The test with a fixed a and two distinct b’s shows that the first halves are equal in 4 with probability exactly 1, whereas for a random 128‑bit permutation (case 1) or AES (case 2) this happens with probability 2^-64. With a single such pair of queries you isolate 4 with overwhelming probability (nearly certainty for 2^-64 error). In the affine branch you don’t even reach this step if the function is affine, so the 4 decision is cleanly separated from 1, 2, and 3 (and is not confused with 5 since 5 is affine).\n", "\n", "- Case 5 vs 3: Both are affine, but 5 has A = I. The two-invocation test f(f(x)) = x is a robust discriminator: for 5, it holds for all x; for most affine 3 cases (A ≠ I), f(f(x)) ≠ x for most x, and two independent probes already give a very high confidence. This separates 5 from 3 very reliably, while preserving the earlier affine/non-affine separation.\n", "\n", "- Case 1 and Case 2: With the plan above, you separate 4 from {1,2} using the half-factorization test. After that, distinguishing 1 from 2 cannot be guaranteed with a fixed finite budget in an unconditional way (see the next section). So, while the plan is excellent for 3, 4, 5, it leaves an intrinsic hardness for 1 vs 2 unless you assume standard cryptographic indistinguishability (which is a computational assumption, not an information-theoretic one).\n", "\n", "Information-theoretic notes and the 1 vs 2 distinction\n", "\n", "- Within the given 2000-query budget and with no extra assumptions, there is no known unconditional, information-theoretic procedure that can reliably distinguish a truly random permutation on 128‑bit strings (case 1) from AES-128 with an unknown key applied to a single 128‑bit block (case 2). Both are permutations of the same domain, and AES is designed to be indistinguishable from random in the standard cryptographic sense for polynomial-time adversaries. Without invoking cryptographic hardness assumptions, one cannot guarantee a bounded‑query distinguisher with non-negligible advantage.\n", "\n", "- If you adopt the standard cryptographic heuristic that AES with an unknown key is a pseudorandom permutation (PRP) indistinguishable from a true random permutation with any polynomially bounded adversary, then there is no bounded-test strategy (in the worst case) that has non-negligible distinguishing advantage between 1 and 2. The advantage would be negligible in the security parameter (128 bits here). Practically, that means: with 2000 queries you should not expect to distinguish 1 from 2 with non-negligible probability; the best you can do is rely on the small statistics you might observe, which are not reliable guarantees.\n", "\n", "- Therefore, in the present framing, you can claim:\n", " - We can reliably separate 3, 4, 5 from each other with a bounded number of queries (6 for the affine check, plus a couple of extra tests for 5 vs 3, plus the 4-vs-1/2 test described).\n", " - We cannot, in general, guarantee distinguishing 1 from 2 with a bounded, unconditional strategy. The most you can do is rely on cryptographic assumptions (PRP indistinguishability) to claim that any such distinction has only negligible advantage.\n", "\n", "- How to modify the problem to make 1 vs 2 distinguishable with bounded queries:\n", " - Remove the cryptographic indistinguishability ambiguity by giving the solver an explicit oracle for a second evaluation of f under a known, new key (i.e., allow reinitialization of the box to a fresh AES instance with a new random key for a second phase). With two unrelated AES instances, you could try to detect the difference between a fully random permutation and AES under a control key schedule. Or,\n", " - Fix the box to be a single random permutation versus a fixed but unknown‑key block cipher, and require that the box cannot simulate the PRP behavior across many inputs in a way indistinguishable from the uniform permutation. Either change yields a setting where you can derive a provable distinguishing strategy (or at least a bounded, provable advantage).\n", "\n", "Minimum number of queries and boundedness\n", "\n", "- The affine test (Stage 0 with 6 queries) plus the involution test (2–4 additional queries in the affine branch) plus the halves test for non-affine (2–3 queries) gives you a practical, concrete protocol that deterministically identifies 3, 4, and 5 with high probability, using on the order of 6–12 queries in total in typical runs.\n", "\n", "- In particular, you can guarantee:\n", " - Case 5 (f(x) = x ⊕ K) vs Case 3 (affine with A ≠ I): high confidence via f∘f tests.\n", " - Case 3 vs Case 4 vs Case 1: clear separation by affine test and then by the halves factorization test.\n", " - Case 1 vs Case 2: not guaranteed with a fixed, small bound; relies on standard cryptographic assumptions (see above).\n", "\n", "- If you want an explicit lower bound statement: No strictly bounded, unconditional strategy can guarantee distinguishing 1 from 2 with non-negligible probability in this setting, because both functions are (to within the natural model) indistinguishable by polynomially many queries. The only way to guarantee a distinction would be to impose a new assumption or change the problem (as described above).\n", "\n", "Putting it together as a concrete protocol\n", "\n", "- Phase 1 (6 queries): affine test\n", " - Query X1 = 0^128, X2 = 0^64||1^64, X3 = X1⊕X2\n", " - Query X4 = 0^64||1^64, X5 = 1^64||0^64, X6 = X4⊕X5\n", " - Compute t1 = f(X1) ⊕ f(X2) ⊕ f(X3), t2 = f(X4) ⊕ f(X5) ⊕ f(X6).\n", " - If t1 ≠ t2, non-affine branch; if t1 = t2, affine branch.\n", "\n", "- Phase 2a (affine branch): separate 5 from 3\n", " - Query X7 = 0^128; observe Y7 = f(X7)\n", " - Query X8 = Y7; observe Z8 = f(X8)\n", " - If Z8 = X7, test a second input X9 = 1^128; Query X10 = f(X9); Query X11 = f(X10); If X or both pass (Z8 = X7 and Z11 = X9), declare 5; else declare 3.\n", " - (Two tests are enough in practice to drive the error probability to negligible levels.)\n", "\n", "- Phase 2b (non-affine branch): separate 4 from {1,2}\n", " - Fixed a = 0^64, b1 = 0^64, b2 = 1^64\n", " - Query X12 = (a,b1), X13 = (a,b2)\n", " - If the first 64 bits of f(X12) and f(X13) are equal, declare 4; else proceed to Phase 2c.\n", " - Phase 2c to separate 1 vs 2 is not guaranteed unconditionally with bounded queries. You either accept a negligible advantage-based separation under PRP indistinguishability (i.e., no practical advantage) or you modify the problem as suggested above.\n", "\n", "Why this strategy satisfies the problem’s requirements\n", "\n", "- It gives a concrete, adaptive plan with explicit inputs for each query, and explicit decision rules on all possible transcripts you might observe (up to the probabilistic caveat for the 1 vs 2 distinction).\n", "- It provides a rigorous justification for why the affine test separates 3/5 from 1/2/4 with overwhelming probability, and why the half-by-half test separates 4 from the others in the non-affine branch.\n", "- It gives a principled argument for why, in the 1 vs 2 subproblem, you cannot guarantee a bounded success probability without additional cryptographic assumptions (hence the discussion about indistinguishability and possible problem modifications).\n", "\n", "If you want a completely foolproof identification of all five cases (including a provable 1 vs 2 distinction), here are two natural modifications you could consider\n", "\n", "- Change the problem to guarantee that the box’s 2 (AES) instance cannot be made indistinguishable from a random permutation under the given query budget (e.g., by providing side information about the key schedule, or requiring multiple keys and independent encryptions). Then you could design a polynomial-time distinguisher with non-negligible advantage; you could then separate 1 and 2 with a bounded query budget.\n", "\n", "- Alternatively, require the box to be reset with a fresh independently chosen permutation for each batch of queries (or to re-keyAES after every block). In that setting, you could exploit changes in mapping across batches to distinguish 1 (static random permutation) from 2 (AES under a fixed key), with guaranteed separation in a bounded number of queries.\n", "\n", "Bottom line\n", "\n", "- A concrete, practical strategy exists to reliably distinguish 3, 4, and 5 within a modest, bounded number of queries (6 for the affine test, plus a few extra tests). Distinguishing 1 from 2 with a small, fixed budget cannot be guaranteed unconditionally; it hinges on standard cryptographic assumptions about AES being indistinguishable from a random permutation. If you’re willing to accept such an assumption, Phase 2 between 1 and 2 becomes a routine PRP indistinguishability test; if not, you must either increase the budget dramatically or modify the problem as described.\n", "Competitor: gemini-2.5-flash\n", "\n", "The task is to design an adaptive querying strategy to distinguish between five types of 128-bit functions with a budget of 2,000 queries, using only paper reasoning.\n", "\n", "Let's first analyze the key properties of each function type:\n", "\n", "1. **Random Permutation (RP):** A truly random, bijective mapping. No discernible structure or pattern for a small number of queries.\n", "2. **AES-128 (ECB mode) (AES):** A pseudorandom permutation (PRP). It's computationally indistinguishable from a random permutation for any adversary with limited computational resources and a reasonable number of queries.\n", "3. **Affine function \\(f(x)=A x \\oplus b\\):** A linear transformation \\(Ax\\) over \\(\\mathbb{F}_2^{128}\\) (where \\(A\\) is an invertible \\(128\\times128\\) binary matrix) followed by an XOR with a constant \\(b\\).\n", " * **Key Property:** For any inputs \\(x_1, x_2\\), \\(f(x_1) \\oplus f(x_2) = A(x_1 \\oplus x_2)\\). This implies that if \\(x_1 \\oplus x_2 = x_3 \\oplus x_4\\), then \\(f(x_1) \\oplus f(x_2) = f(x_3) \\oplus f(x_4)\\). More specifically, for a fixed \\(\\Delta \\ne 0\\), the output difference \\(f(x \\oplus \\Delta) \\oplus f(x)\\) is constant for all \\(x\\).\n", "4. **Split Random Permutation \\(f(x)=g(x_L)\\,\\|\\,h(x_R)\\):** The input \\(x\\) is split into a 64-bit left part \\(x_L\\) and a 64-bit right part \\(x_R\\). The output is formed by concatenating \\(g(x_L)\\) and \\(h(x_R)\\), where \\(g\\) and \\(h\\) are independent random permutations on 64-bit strings.\n", " * **Key Property:** If \\(x_L\\) is held constant, then the left 64 bits of the output \\(g(x_L)\\) remain constant, regardless of changes in \\(x_R\\). Similarly, if \\(x_R\\) is held constant, the right 64 bits of the output \\(h(x_R)\\) remain constant.\n", "5. **XOR with a fixed key \\(f(x)=x\\oplus K\\):** A very simple affine function where \\(A\\) is the identity matrix.\n", " * **Key Property:** For any inputs \\(x_1, x_2\\), \\(f(x_1) \\oplus f(x_2) = (x_1 \\oplus K) \\oplus (x_2 \\oplus K) = x_1 \\oplus x_2\\). The output difference is always equal to the input difference.\n", "\n", "**Strategy Overview:**\n", "\n", "The strategy will involve a sequence of adaptive tests, moving from the most specific and easily detectable properties (XOR) to more general ones (Affine, Split RP). If none of these specific patterns are detected, the function is classified as either AES or Random Permutation, which are considered indistinguishable under the given constraints. Each test is designed to exploit a unique structural property that is highly unlikely to occur by chance in other function types (especially RP or AES).\n", "\n", "**Notation:**\n", "* `Q(x)`: Submit input `x` and observe the output.\n", "* `y[L]`: The first 64 bits of a 128-bit value `y`.\n", "* `y[R]`: The last 64 bits of a 128-bit value `y`.\n", "\n", "---\n", "\n", "**Detailed Adaptive Querying Strategy:**\n", "\n", "We will use a total of **9 queries** to identify Cases 3, 4, or 5 with very high probability. If none of these are identified, we classify it as Case 1 or 2.\n", "\n", "**Phase 1: Test for Case 5 (XOR with a fixed key)**\n", "This is the strongest structural property.\n", "1. **Query 1:** Set \\(x_1 = 0^{128}\\) (all zeros). Query \\(Q(x_1)\\), observe \\(y_1\\).\n", "2. **Query 2:** Set \\(x_2 = 0^{127}1\\) (value 1). Query \\(Q(x_2)\\), observe \\(y_2\\).\n", "3. **Query 3:** Set \\(x_3 = 0^{126}10\\) (value 2). Query \\(Q(x_3)\\), observe \\(y_3\\).\n", "\n", "* **Decision Rule for XOR:**\n", " If \\((y_2 \\oplus y_1 = x_2 \\oplus x_1)\\) AND \\((y_3 \\oplus y_1 = x_3 \\oplus x_1)\\):\n", " **Declare Case 5 (XOR)**. Stop.\n", "* **Justification:** For \\(f(x)=x \\oplus K\\), these conditions must hold (e.g., \\(f(1) \\oplus f(0) = (1 \\oplus K) \\oplus (0 \\oplus K) = 1 \\oplus 0 = 1\\)). For a random permutation, AES, affine function with \\(A \\ne I\\), or split RP, the probability of satisfying these two conditions is approximately \\((1/2^{128}) \\times (1/2^{128}) = 1/2^{256}\\). This is an astronomically low probability of false positive.\n", "\n", "**Phase 2: Test for Case 3 (Affine function)**\n", "This phase is executed only if Case 5 was NOT identified in Phase 1.\n", "4. **Query 4:** Choose a fixed difference \\(\\Delta = 0^{125}100\\) (value 4). This value is distinct from \\(x_1, x_2, x_3\\). Set \\(x_4 = x_1 \\oplus \\Delta = 0 \\oplus 4 = 4\\). Query \\(Q(x_4)\\), observe \\(y_4\\).\n", "5. **Query 5:** Set \\(x_5 = x_2 \\oplus \\Delta = 1 \\oplus 4 = 5\\). Query \\(Q(x_5)\\), observe \\(y_5\\).\n", "6. **Query 6:** Set \\(x_6 = x_3 \\oplus \\Delta = 2 \\oplus 4 = 6\\). Query \\(Q(x_6)\\), observe \\(y_6\\).\n", " (All inputs \\(x_1 \\dots x_6\\) are distinct: 0, 1, 2, 4, 5, 6).\n", "\n", "* **Decision Rule for Affine:**\n", " Let \\(D_0 = y_4 \\oplus y_1\\). (This is the candidate value for \\(A\\Delta\\)).\n", " If \\((y_5 \\oplus y_2 = D_0)\\) AND \\((y_6 \\oplus y_3 = D_0)\\):\n", " **Declare Case 3 (Affine)**. Stop.\n", "* **Justification:** For \\(f(x)=Ax \\oplus b\\), the value \\(f(x \\oplus \\Delta) \\oplus f(x)\\) must be constant for a fixed \\(\\Delta\\) (it equals \\(A\\Delta\\)). So, \\(y_4 \\oplus y_1\\) must equal \\(y_5 \\oplus y_2\\), which must equal \\(y_6 \\oplus y_3\\). The probability of these two equalities holding by chance for a random permutation, AES, or split RP is approximately \\((1/2^{128}) \\times (1/2^{128}) = 1/2^{256}\\).\n", "\n", "**Phase 3: Test for Case 4 (Split Random Permutation)**\n", "This phase is executed only if Case 5 and Case 3 were NOT identified.\n", "7. **Query 7:** Define \\(\\Delta_L = (1 \\ll 127)\\), which is the most significant bit of the left 64 bits set to 1. Set \\(x_7 = x_1 \\oplus \\Delta_L = \\Delta_L\\). Query \\(Q(x_7)\\), observe \\(y_7\\).\n", "8. **Query 8:** Define \\(\\Delta_R = (1 \\ll 63)\\), which is the most significant bit of the right 64 bits set to 1. Set \\(x_8 = x_1 \\oplus \\Delta_R = \\Delta_R\\). Query \\(Q(x_8)\\), observe \\(y_8\\).\n", "9. **Query 9:** Set \\(x_9 = x_1 \\oplus \\Delta_L \\oplus \\Delta_R = \\Delta_L \\oplus \\Delta_R\\). Query \\(Q(x_9)\\), observe \\(y_9\\).\n", " (All inputs \\(x_1 \\dots x_9\\) are distinct: 0, 1, 2, 4, 5, 6, \\(\\Delta_L\\), \\(\\Delta_R\\), \\(\\Delta_L \\oplus \\Delta_R\\)).\n", "\n", "* **Decision Rule for Split RP:**\n", " If \\((y_7[R] = y_1[R])\\) AND \\((y_8[L] = y_1[L])\\) AND \\((y_9[L] = y_7[L])\\) AND \\((y_9[R] = y_8[R])\\):\n", " **Declare Case 4 (Split RP)**. Stop.\n", "* **Justification:** For \\(f(x)=g(x_L)\\,\\|\\,h(x_R)\\):\n", " * \\(x_R(x_7) = x_R(\\Delta_L) = 0\\), and \\(x_R(x_1) = x_R(0) = 0\\). So \\(y_7[R] = h(0)\\) and \\(y_1[R] = h(0)\\). They must be equal. (Prob for RP/AES/Affine: \\(1/2^{64}\\)).\n", " * \\(x_L(x_8) = x_L(\\Delta_R) = 0\\), and \\(x_L(x_1) = x_L(0) = 0\\). So \\(y_8[L] = g(0)\\) and \\(y_1[L] = g(0)\\). They must be equal. (Prob for RP/AES/Affine: \\(1/2^{64}\\)).\n", " * \\(x_L(x_9) = x_L(\\Delta_L \\oplus \\Delta_R) = x_L(\\Delta_L)\\). So \\(y_9[L] = g(x_L(\\Delta_L)) = y_7[L]\\). This condition holds with probability 1 for Split RP. For RP/AES/Affine, \\(y_9[L]\\) would be a new random 64-bit value, so probability of match is \\(1/2^{64}\\).\n", " * \\(x_R(x_9) = x_R(\\Delta_L \\oplus \\Delta_R) = x_R(\\Delta_R)\\). So \\(y_9[R] = h(x_R(\\Delta_R)) = y_8[R]\\). This condition also holds with probability 1 for Split RP. For RP/AES/Affine, \\(y_9[R]\\) would be a new random 64-bit value, so probability of match is \\(1/2^{64}\\).\n", " The combined probability of all four conditions occurring by chance for RP/AES/Affine is approximately \\((1/2^{64})^4 = 1/2^{256}\\).\n", "\n", "**Phase 4: Indistinguishable Cases (RP or AES-128)**\n", "This phase is executed only if none of the specific patterns were identified in Phases 1-3.\n", "\n", "* **Decision Rule for RP/AES:**\n", " If none of the above conditions are met after 9 queries:\n", " **Declare Cases 1 or 2 (Indistinguishable: Random Permutation or AES-128)**. Stop.\n", "* **Justification:**\n", " * **Computational Indistinguishability:** AES is designed to be a strong pseudorandom permutation (PRP). For an adversary with \"paper reasoning\" (i.e., no computational resources to perform complex statistical analyses) and a limited number of queries (2,000 queries is very small compared to the \\(2^{128}\\) domain size), AES-128 is computationally indistinguishable from a truly random permutation. Any simple statistical test that could be performed manually (e.g., checking for immediate collisions or very short cycles) would fail to distinguish them with 2,000 queries due to the vast domain.\n", " * **Information-Theoretic Indistinguishability:** There is no known structural property of AES that would manifest within 2,000 queries (or even a much larger number, like \\(2^{64}\\)) that is simple enough to be detected by \"paper reasoning\" and not also be present in a random permutation with high probability, or ruled out by previous tests. The specific structural properties of AES (e.g., S-boxes, mix columns, key schedule) are designed to diffuse input changes rapidly, preventing simple patterns from emerging.\n", "\n", "---\n", "\n", "**Summary of Queries and Success Probability:**\n", "\n", "* **Minimum Queries:** 3 (if XOR), 6 (if Affine), or 9 (if Split RP or RP/AES).\n", "* **Maximum Queries Used:** 9. The strategy is well within the 2,000 query budget.\n", "* **Success Probability:**\n", " * For XOR, Affine, and Split RP functions, the probability of correctly identifying them is extremely high (error probability of roughly \\(1/2^{256}\\) for each, due to false positives from other types).\n", " * For Random Permutation and AES-128, the strategy groups them as \"indistinguishable\". This maximizes success probability because, given the constraints (2,000 queries, paper reasoning), there's no reliable way to tell them apart. If a single distinct answer is required for all five, then the success probability for these two cases would be very low (e.g., 50% if forced to guess), as there are no distinguishing features discoverable under the given conditions.\n", "\n", "---\n", "\n", "**Modifications to make AES/RP distinguishable:**\n", "\n", "To make AES-128 and a uniformly random permutation distinguishable with a high success probability, one would need to alter the problem constraints significantly:\n", "\n", "1. **Increased Query Budget:** A much larger query budget, ideally in the order of \\(2^{64}\\) or more, would allow an adversary to perform statistical tests (like chi-squared tests on output distributions, birthday attacks on internal states, or more advanced cryptanalytic techniques) that could detect non-randomness in AES.\n", "2. **Computational Resources:** Allowing computational resources would enable an adversary to process and analyze the outputs of thousands or millions of queries, looking for subtle statistical biases or patterns that are characteristic of AES but not of a truly random function. \"Paper reasoning\" explicitly rules out such analysis.\n", "3. **Known Plaintext/Ciphertext Pairs for AES:** If the adversary had access to known plaintext/ciphertext pairs for the specific AES key, they could compare them against the black box's output, thus confirming AES.\n", "4. **Side-Channel Information:** Access to side-channel information (e.g., timing, power consumption, electromagnetic radiation) during the black box's computation of \\(f(x)\\) could easily distinguish AES from a hypothetical \"truly random\" hardware implementation.\n", "Competitor: qwen3.6-flash\n", "\n", "### Executive Summary\n", "To distinguish between the five cases with the highest possible success probability, only **4 adaptive queries** are sufficient. This strategy exploits the specific algebraic and structural properties of each function to rule out candidates efficiently.\n", "\n", "The identification follows a strict hierarchy:\n", "1. **Case 5 (XOR Mask):** Detected via constant differential properties.\n", "2. **Case 4 (Split Permutation):** Detected via partial independence (changing half the input does not change the other half of the output).\n", "3. **Case 3 (Affine):** Detected via additive relationships (XOR sums of inputs equal XOR sums of outputs).\n", "4. **Cases 1 & 2 (Random Perm / AES):** These are information-theoretically indistinguishable within the given budget.\n", "\n", "---\n", "\n", "### Detailed Adaptive Querying Strategy\n", "\n", "#### Phase 1: Initialization\n", "We begin by defining four basis vectors to probe the function's linearity and bit-dependency.\n", "1. **Query 1 ($x_0$):** Submit `00...00` (128 zeros). Receive $y_0$.\n", "2. **Query 2 ($x_1$):** Submit `10...00` (Bit 127 set; Upper Half). Receive $y_1$.\n", "3. **Query 3 ($x_2$):** Submit `00...01` (Bit 0 set; Lower Half). Receive $y_2$.\n", "\n", "At this point, we have evaluated the function at the origin and at two orthogonal unit vectors.\n", "\n", "#### Phase 2: Sequential Decision Rules\n", "\n", "**Step 1: Check for Case 5 (XOR Mask)**\n", "A function in Case 5 satisfies $f(x) = x \\oplus K$. Thus, $f(x) \\oplus x$ must equal the constant vector $K$.\n", "* **Compute Candidate Keys:**\n", " * $K_0 = y_0 \\oplus 0 = y_0$\n", " * $K_1 = y_1 \\oplus x_1$\n", " * $K_2 = y_2 \\oplus x_2$\n", "* **Decision Rule:**\n", " * If **$K_0 = K_1 = K_2$**, identify **Case 5**. Terminate.\n", " * Otherwise, proceed to Step 2.\n", " * *Reasoning:* In Case 5, this equality holds with probability 1. In all other cases, the probability of this happening for 3 points is roughly $2^{-384}$.\n", "\n", "**Step 2: Check for Case 4 (Split Permutation)**\n", "A function in Case 4 is separable: $f(x_L, x_R) = (\\pi_1(x_L), \\pi_2(x_R))$.\n", "* **Property:** Changing the Upper Input ($x_L$) should **not** affect the Lower Output ($Y_R$). Conversely, changing the Lower Input ($x_R$) should **not** affect the Upper Output ($Y_L$).\n", "* **Action:** Compare the halves of the received outputs.\n", " 1. Extract the Lower 64 bits of $y_1$ and $y_0$.\n", " 2. Extract the Upper 64 bits of $y_2$ and $y_0$.\n", "* **Decision Rule:**\n", " * If (Lower half of $y_1$ == Lower half of $y_0$) **AND** (Upper half of $y_2$ == Upper half of $y_0$), identify **Case 4**. Terminate.\n", " * Otherwise, proceed to Step 3.\n", " * *Reasoning:* This specific structural independence holds for Case 4. It fails for random or fully mixed functions with probability $1 - 2^{-64}$.\n", "\n", "**Step 3: Check for Case 3 (Affine Transformation)**\n", "If the first two tests fail, we check for linearity. Case 3 functions satisfy $f(A \\oplus B) = f(A) \\oplus f(B) \\oplus f(0)$.\n", "* **Action:**\n", " 1. Compute the target XOR sum: $Target = y_0 \\oplus y_1 \\oplus y_2$.\n", " 2. **Query 4 ($x_3$):** Submit $x_1 \\oplus x_2$ (bits 127 and 0 set). Receive $y_3$.\n", "* **Decision Rule:**\n", " * If **$y_3 = Target$**, identify **Case 3**. Terminate.\n", " * Otherwise, proceed to Final Assessment.\n", " * *Reasoning:* This check verifies the affine homomorphism property. While Case 5 also satisfies this, it was ruled out in Step 1.\n", "\n", "**Final Assessment: Case 1 or 2**\n", "If all structural checks fail, the function lacks the algebraic structure of 3, 4, or 5.\n", "* **Identification:** **Case 1 (Random Permutation) or Case 2 (AES-128).**\n", "* *Reasoning:* Both are permutations with no detectable bias under this query budget.\n", "\n", "---\n", "\n", "### Justification\n", "\n", "1. **Case 5 (Linear/XOR):** Defined by a constant differential. Any deviation in $f(x) \\oplus x$ rules it out.\n", "2. **Case 4 (Separable):** Defined by independent sub-spaces. Testing coordinate independence is a definitive structural signature.\n", "3. **Case 3 (Affine):** Defined by linear superposition. The XOR-additivity check $f(x \\oplus y) \\oplus f(x) \\oplus f(y) \\oplus f(0) = 0$ is a rigorous mathematical test for affine maps.\n", "4. **Cases 1 vs 2:** Distinguishability relies on finding statistical deviations from randomness. AES-128 is a Pseudorandom Permutation (PRP); its outputs are computationally indistinguishable from a truly Random Permutation. With a budget of 2,000 queries (significantly below the birthday bound of $2^{64}$), no information-theoretic distinguisher exists.\n", "\n", "---\n", "\n", "### Indistinguishability of Cases 1 and 2\n", "\n", "**Why they are indistinguishable:**\n", "Under the given constraints, Case 1 and Case 2 are information-theoretically indistinguishable. A secure block cipher like AES is designed specifically to mimic a Random Permutation. With $N=2000$ queries, the statistical distance between the output distribution of AES and a Uniform Random Permutation is vanishingly small (advantage $\\approx N^2/2^{128}$).\n", "\n", "**Proposed Problem Modifications to Enable Distinction:**\n", "To make Case 1 distinguishable from Case 2, one could:\n", "1. **Increase Query Budget Exponentially:** Raising the query limit to $\\ge 2^{64}$ would allow the observation of collisions or statistical biases inherent in the construction, though this remains computationally difficult.\n", "2. **Alter Case 1 (Null Hypothesis):** Replace \"Random Permutation\" with **\"Random Function\"**. A Random Function allows collisions ($f(x) = f(y)$ for $x \\neq y$), while AES (Case 2) remains a permutation. Checking for output collisions would instantly identify Case 1.\n", "3. **Alter Case 2 (Weak Cipher):** Specify AES with a **weak key** (e.g., $K=0$) or a known variation with a known distinguisher (e.g., a specific linear trail), allowing manual verification.\n" ] } ], "source": [ "# It's nice to know how to use \"zip\"\n", "for competitor, answer in zip(competitors, answers):\n", " print(f\"Competitor: {competitor}\\n\\n{answer}\")\n" ] }, { "cell_type": "code", "execution_count": 57, "metadata": {}, "outputs": [], "source": [ "# Let's bring this together - note the use of \"enumerate\"\n", "\n", "together = \"\"\n", "for index, answer in enumerate(answers):\n", " together += f\"# Response from competitor {index+1}\\n\\n\"\n", " together += answer + \"\\n\\n\"" ] }, { "cell_type": "code", "execution_count": 58, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "# Response from competitor 1\n", "\n", "Below is a concrete, adaptive strategy that (i) uses a bounded number of 128‑bit queries, (ii) works for all five possibilities with high probability, and (iii) makes explicit the transcript-based decision rules. I also include a careful discussion of what can and cannot be guaranteed with the given budget, and how you could modify the problem if you want a provable distinction in all five cases.\n", "\n", "High-level plan (what we try to separate and why)\n", "\n", "- A quick affine/linear test lets us separate the “affine” family f(x) = A x ⊕ b from all the genuinely non‑affine possibilities (cases 1, 2, 4). This immediately distinguishes 5 (A = I, b = K) from all non‑affine cases with very high probability, and separates 3 (A arbitrary invertible) from 5.\n", "\n", "- If we flag affine and the test is consistent with A = I (the XOR-with-a-constant family), we can separate case 5 from the rest of the affine family using a small extra test (involution style): for case 5, f∘f = id; for generic affine (case 3 with A ≠ I), f∘f is not the identity for almost all inputs (and we can detect this with a couple of probes). This gives a robust way to distinguish 5 from 3, while still keeping error probability negligible.\n", "\n", "- If we flag non-affine (i.e., not in affine form), we can separate case 4 from cases 1 and 2 using a simple “factorization by halves” observation: in case 4, the first output half depends only on the first input half, and the second output half depends only on the second input half (g and h are independent 64‑bit permutations). In contrast, a random 128‑bit permutation (case 1) and AES in ECB (case 2) do not factorize this way. With a single carefully chosen pair of queries having the same first input half but different second halves, the first output half should be identical for 4 but not for 1 or 2 with overwhelming probability (2^-64 type small error). This lets us separate 4 from {1,2} with high confidence.\n", "\n", "- Distinguishing 1 vs 2 (uniform random permutation vs AES with an unknown key) cannot be guaranteed to succeed with a bounded, small query budget under standard cryptographic indistinguishability assumptions; both look like random permutations on the 128‑bit domain to any polynomially bounded test. I flag this explicitly and explain how you could modify the task if you want a provable separation in all five cases.\n", "\n", "Now the detailed strategy\n", "\n", "1) Meet-the-affine test (to pull case 3, 5 apart from 1, 2, 4)\n", "\n", "- Query preparation (6 inputs use, two independent triple tests to check affine structure):\n", " - Let X1 = 0^128 (all zero 128 bits).\n", " - Let X2 = 0^64 || 1^64 (first 64 bits zero, last 64 bits all ones).\n", " - Let X3 = X1 ⊕ X2 = 0^64 || 1^64 (note X3 ≠ X1, X3 ≠ X2).\n", "\n", " - Let X4 = 0^64 || 1^64 (the same as X2 for convenience; we’ll avoid accidental dependence by the second triple using a different base).\n", " - Let X5 = 1^64 || 0^64 (first half all ones, second half all zeros).\n", " - Let X6 = X4 ⊕ X5 = (1^64 || 1^64).\n", "\n", " The two triples are (X1, X2, X3) and (X4, X5, X6). They give two independent checks of the same affine-structure quantity.\n", "\n", "- For a generic affine function f(x) = A x ⊕ b over GF(2)^128, we have for any x,y:\n", " f(x) ⊕ f(y) ⊕ f(x ⊕ y) = b.\n", " Therefore, if f is affine, the 128‑bit value\n", " T(x,y) = f(x) ⊕ f(y) ⊕ f(x ⊕ y)\n", " is constant and equal to b, for all x,y. So for the two triples, we should observe\n", " t1 = f(X1) ⊕ f(X2) ⊕ f(X3) = b,\n", " t2 = f(X4) ⊕ f(X5) ⊕ f(X6) = b,\n", " hence t1 = t2 with extremely high probability (the only way they could differ is a ceil(2^-128)‑level collision across two independent evaluations).\n", "\n", "- What you actually do (queries and transcript):\n", " - Query 1: input X1 = 0^128; observe Y1 = f(X1).\n", " - Query 2: input X2 = 0^64 || 1^64; observe Y2 = f(X2).\n", " - Query 3: input X3 = X1 ⊕ X2; observe Y3 = f(X3).\n", " - Compute t1 = Y1 ⊕ Y2 ⊕ Y3.\n", "\n", " - Query 4: input X4 = 0^64 || 1^64; observe Y4 = f(X4).\n", " - Query 5: input X5 = 1^64 || 0^64; observe Y5 = f(X5).\n", " - Query 6: input X6 = X4 ⊕ X5; observe Y6 = f(X6).\n", " - Compute t2 = Y4 ⊕ Y5 ⊕ Y6.\n", "\n", "- Decision rule after 6 queries:\n", " - If t1 = t2 (down to exact bit equality, within machine precision), classify as affine (candidate 3 or 5).\n", " - If t1 ≠ t2, classify as non-affine (candidate 1, 2, or 4).\n", "\n", "Notes:\n", "- The probability that a non-affine function yields t1 = t2 for both triples is at most about 2^-128, so this yields a clean separation in practice.\n", "- If you want a safer margin, you can repeat the test with another independent pair of triples (costing a few more queries) and require two out of three to agree; with 2000 total budget this is still cheap and provides overwhelming confidence.\n", "\n", "2) If affine: separate 5 from 3 (robustly)\n", "\n", "- We are in the affine branch (t1 = t2). Now determine if A = I (i.e., f(x) = x ⊕ b) or not (i.e., f is a nontrivial affine map).\n", "- A simple, robust check is to test whether f∘f is the identity on a small, random subset of inputs. For f(x) = A x ⊕ b, one has\n", " f(f(x)) = A(Ax ⊕ b) ⊕ b = A^2 x ⊕ A b ⊕ b.\n", " In general, unless A^2 = I and A b = b, this will not equal x for most x.\n", "\n", "- Practical two-input involution tests (two queries suffice per test):\n", " - Test 1: Query x = 0^128, get y = f(x). Query z = f(y) and compare z with x.\n", " - For case 5 (A = I, f(x) = x ⊕ b with b ≡ K), f(f(0)) = 0, so z = 0 = x.\n", " - For most affine cases with A ≠ I, f(f(0)) ≠ 0.\n", " - Test 2: If Test 1 passed (z = x), test with another input x' = 1^128 (or any nonzero x) in the same way:\n", " - Compute y' = f(x'), z' = f(y'), check whether z' = x'.\n", " - Decision after two tests:\n", " - If both tests produce f(f(x)) = x for the two chosen x’s, declare 5.\n", " - If any test yields f(f(x)) ≠ x for some chosen x, declare 3.\n", "\n", "Notes and robustness:\n", "- It is possible in principle (though with small probability) that some affine maps with A ≠ I and a particular b satisfy f∘f = id for a few special x; to guard against that, you can choose two distinct nonzero inputs (as above) and require both pass; the probability that both pass for A ≠ I is still negligible in GF(2)^128.\n", "- If you want even stronger confidence you could test a third input as well, but two such tests already give overwhelming confidence that A ≠ I is unlikely and that you truly have 5 when all tests pass.\n", "\n", "3) If non-affine: separate 4 from {1, 2}\n", "\n", "- Now we are in the non-affine branch (cases 1, 2, 4). Use the “factorization by halves” property to pull out 4.\n", "\n", "- Choose a fixed first-half value a ∈ {0,1}^64 and two distinct second-half values b1 ≠ b2 ∈ {0,1}^64.\n", " - Query X = (a, b1) and Y = (a, b2). Observe F(X) and F(Y), each 128 bits.\n", "\n", "- Compare the first 64 bits of F(X) and F(Y).\n", "\n", "- Decision rule:\n", " - If the first halves of F(X) and F(Y) are identical, declare 4 with high confidence (the first output half in case 4 depends only on the first input half a; varying the second half b does not affect the first output half). The probability that the first halves match by accident for a random 128‑bit permutation (cases 1 or 2) is 2^-64, which is negligible. \n", " - If the first halves are different, declare not-4; the remaining possibilities are 1 or 2.\n", "\n", "- Distinguishing 1 vs 2 after ruling out 4:\n", " - This is the tricky part. With only 2000 queries, there is no known information-theoretic guarantee (under standard cryptographic assumptions) that you can distinguish a truly random 128‑bit permutation from AES-128 with an unknown key, because AES is designed to be a pseudorandom permutation indistinguishable from a random permutation with polynomially many queries. Hence, there is no bounded-number, deterministic strategy that, in the worst case, distinguishes 1 from 2 with non-negligible advantage. In practice, any such attempt relies on cryptanalytic assumptions rather than unconditional reasoning.\n", "\n", "- Practical stance for this subproblem:\n", " - If one accepts the standard cryptographic heuristic that AES with an unknown key is indistinguishable from a random permutation for polynomially many queries, then after you have eliminated 4, you should treat the remaining options as essentially indistinguishable within the given query budget. Your best operational choice then is to guess between 1 and 2 (e.g., random guess, or a fixed guess), accepting an impossibility to guarantee correctness better than random guessing. The failure probability would be roughly 1/2 for this last step, as long as you have not observed any distinguishing signature.\n", " - If you are allowed to modify the problem (see below), you could make this final distinction provable.\n", "\n", "Summary of the adaptive query plan and transcript rules\n", "\n", "- Total queries used for the affine test (Stage A): 6 queries\n", " - Q1: X1 = 0^128\n", " - Q2: X2 = 0^64 || 1^64\n", " - Q3: X3 = X1 ⊕ X2\n", " - Q4: X4 = 0^64 || 1^64\n", " - Q5: X5 = 1^64 || 0^64\n", " - Q6: X6 = X4 ⊕ X5\n", " - Transcript check: t1 = f(X1) ⊕ f(X2) ⊕ f(X3); t2 = f(X4) ⊕ f(X5) ⊕ f(X6).\n", " - If t1 = t2 → affine branch; else non-affine branch.\n", "\n", "- If affine (t1 = t2):\n", " - Test involution on two inputs:\n", " - Q7: X7 = 0^128; observe f(X7) = Y7\n", " - Q8: X8 = Y7; observe Z8 = f(X8)\n", " - Check whether Z8 = X7 (i.e., f(f(0)) = 0)\n", " - Q9: X9 = 1^128; observe Y9; Q10: f(Y9) to get Z10; check whether Z10 = X9\n", " - Decision after Q8–Q10:\n", " - If both Z8 = X7 and Z10 = X9, declare 5.\n", " - If any of these fails, declare 3.\n", "\n", "- If non-affine (t1 ≠ t2):\n", " - Test halves-invariance to pull out 4:\n", " - Q11: X11 = (a, b1) with a = 0^64, b1 = 0^64\n", " - Q12: X12 = (a, b2) with a = 0^64, b2 = 1^64\n", " - Compare first 64 bits of f(X11) and f(X12)\n", " - Decision after Q12:\n", " - If first halves match, declare 4.\n", " - If first halves differ, declare either 1 or 2 (no reliable unconditional method to distinguish them with a fixed small budget; see caveats below).\n", "\n", "- If you want a concrete final decision between 1 and 2 under this plan, you would need to invoke an unproven cryptographic assumption (PRP indistinguishability) or allow a far larger query budget. The plan above gives a robust, provably correct identification for 3, 4, 5, and a heuristic/PRP-based approach for 1 vs 2.\n", "\n", "Why this distinguishes cases 3–5 better than random guessing\n", "\n", "- Case 4 vs others: The first output half in case 4 depends only on the first input half. The test with a fixed a and two distinct b’s shows that the first halves are equal in 4 with probability exactly 1, whereas for a random 128‑bit permutation (case 1) or AES (case 2) this happens with probability 2^-64. With a single such pair of queries you isolate 4 with overwhelming probability (nearly certainty for 2^-64 error). In the affine branch you don’t even reach this step if the function is affine, so the 4 decision is cleanly separated from 1, 2, and 3 (and is not confused with 5 since 5 is affine).\n", "\n", "- Case 5 vs 3: Both are affine, but 5 has A = I. The two-invocation test f(f(x)) = x is a robust discriminator: for 5, it holds for all x; for most affine 3 cases (A ≠ I), f(f(x)) ≠ x for most x, and two independent probes already give a very high confidence. This separates 5 from 3 very reliably, while preserving the earlier affine/non-affine separation.\n", "\n", "- Case 1 and Case 2: With the plan above, you separate 4 from {1,2} using the half-factorization test. After that, distinguishing 1 from 2 cannot be guaranteed with a fixed finite budget in an unconditional way (see the next section). So, while the plan is excellent for 3, 4, 5, it leaves an intrinsic hardness for 1 vs 2 unless you assume standard cryptographic indistinguishability (which is a computational assumption, not an information-theoretic one).\n", "\n", "Information-theoretic notes and the 1 vs 2 distinction\n", "\n", "- Within the given 2000-query budget and with no extra assumptions, there is no known unconditional, information-theoretic procedure that can reliably distinguish a truly random permutation on 128‑bit strings (case 1) from AES-128 with an unknown key applied to a single 128‑bit block (case 2). Both are permutations of the same domain, and AES is designed to be indistinguishable from random in the standard cryptographic sense for polynomial-time adversaries. Without invoking cryptographic hardness assumptions, one cannot guarantee a bounded‑query distinguisher with non-negligible advantage.\n", "\n", "- If you adopt the standard cryptographic heuristic that AES with an unknown key is a pseudorandom permutation (PRP) indistinguishable from a true random permutation with any polynomially bounded adversary, then there is no bounded-test strategy (in the worst case) that has non-negligible distinguishing advantage between 1 and 2. The advantage would be negligible in the security parameter (128 bits here). Practically, that means: with 2000 queries you should not expect to distinguish 1 from 2 with non-negligible probability; the best you can do is rely on the small statistics you might observe, which are not reliable guarantees.\n", "\n", "- Therefore, in the present framing, you can claim:\n", " - We can reliably separate 3, 4, 5 from each other with a bounded number of queries (6 for the affine check, plus a couple of extra tests for 5 vs 3, plus the 4-vs-1/2 test described).\n", " - We cannot, in general, guarantee distinguishing 1 from 2 with a bounded, unconditional strategy. The most you can do is rely on cryptographic assumptions (PRP indistinguishability) to claim that any such distinction has only negligible advantage.\n", "\n", "- How to modify the problem to make 1 vs 2 distinguishable with bounded queries:\n", " - Remove the cryptographic indistinguishability ambiguity by giving the solver an explicit oracle for a second evaluation of f under a known, new key (i.e., allow reinitialization of the box to a fresh AES instance with a new random key for a second phase). With two unrelated AES instances, you could try to detect the difference between a fully random permutation and AES under a control key schedule. Or,\n", " - Fix the box to be a single random permutation versus a fixed but unknown‑key block cipher, and require that the box cannot simulate the PRP behavior across many inputs in a way indistinguishable from the uniform permutation. Either change yields a setting where you can derive a provable distinguishing strategy (or at least a bounded, provable advantage).\n", "\n", "Minimum number of queries and boundedness\n", "\n", "- The affine test (Stage 0 with 6 queries) plus the involution test (2–4 additional queries in the affine branch) plus the halves test for non-affine (2–3 queries) gives you a practical, concrete protocol that deterministically identifies 3, 4, and 5 with high probability, using on the order of 6–12 queries in total in typical runs.\n", "\n", "- In particular, you can guarantee:\n", " - Case 5 (f(x) = x ⊕ K) vs Case 3 (affine with A ≠ I): high confidence via f∘f tests.\n", " - Case 3 vs Case 4 vs Case 1: clear separation by affine test and then by the halves factorization test.\n", " - Case 1 vs Case 2: not guaranteed with a fixed, small bound; relies on standard cryptographic assumptions (see above).\n", "\n", "- If you want an explicit lower bound statement: No strictly bounded, unconditional strategy can guarantee distinguishing 1 from 2 with non-negligible probability in this setting, because both functions are (to within the natural model) indistinguishable by polynomially many queries. The only way to guarantee a distinction would be to impose a new assumption or change the problem (as described above).\n", "\n", "Putting it together as a concrete protocol\n", "\n", "- Phase 1 (6 queries): affine test\n", " - Query X1 = 0^128, X2 = 0^64||1^64, X3 = X1⊕X2\n", " - Query X4 = 0^64||1^64, X5 = 1^64||0^64, X6 = X4⊕X5\n", " - Compute t1 = f(X1) ⊕ f(X2) ⊕ f(X3), t2 = f(X4) ⊕ f(X5) ⊕ f(X6).\n", " - If t1 ≠ t2, non-affine branch; if t1 = t2, affine branch.\n", "\n", "- Phase 2a (affine branch): separate 5 from 3\n", " - Query X7 = 0^128; observe Y7 = f(X7)\n", " - Query X8 = Y7; observe Z8 = f(X8)\n", " - If Z8 = X7, test a second input X9 = 1^128; Query X10 = f(X9); Query X11 = f(X10); If X or both pass (Z8 = X7 and Z11 = X9), declare 5; else declare 3.\n", " - (Two tests are enough in practice to drive the error probability to negligible levels.)\n", "\n", "- Phase 2b (non-affine branch): separate 4 from {1,2}\n", " - Fixed a = 0^64, b1 = 0^64, b2 = 1^64\n", " - Query X12 = (a,b1), X13 = (a,b2)\n", " - If the first 64 bits of f(X12) and f(X13) are equal, declare 4; else proceed to Phase 2c.\n", " - Phase 2c to separate 1 vs 2 is not guaranteed unconditionally with bounded queries. You either accept a negligible advantage-based separation under PRP indistinguishability (i.e., no practical advantage) or you modify the problem as suggested above.\n", "\n", "Why this strategy satisfies the problem’s requirements\n", "\n", "- It gives a concrete, adaptive plan with explicit inputs for each query, and explicit decision rules on all possible transcripts you might observe (up to the probabilistic caveat for the 1 vs 2 distinction).\n", "- It provides a rigorous justification for why the affine test separates 3/5 from 1/2/4 with overwhelming probability, and why the half-by-half test separates 4 from the others in the non-affine branch.\n", "- It gives a principled argument for why, in the 1 vs 2 subproblem, you cannot guarantee a bounded success probability without additional cryptographic assumptions (hence the discussion about indistinguishability and possible problem modifications).\n", "\n", "If you want a completely foolproof identification of all five cases (including a provable 1 vs 2 distinction), here are two natural modifications you could consider\n", "\n", "- Change the problem to guarantee that the box’s 2 (AES) instance cannot be made indistinguishable from a random permutation under the given query budget (e.g., by providing side information about the key schedule, or requiring multiple keys and independent encryptions). Then you could design a polynomial-time distinguisher with non-negligible advantage; you could then separate 1 and 2 with a bounded query budget.\n", "\n", "- Alternatively, require the box to be reset with a fresh independently chosen permutation for each batch of queries (or to re-keyAES after every block). In that setting, you could exploit changes in mapping across batches to distinguish 1 (static random permutation) from 2 (AES under a fixed key), with guaranteed separation in a bounded number of queries.\n", "\n", "Bottom line\n", "\n", "- A concrete, practical strategy exists to reliably distinguish 3, 4, and 5 within a modest, bounded number of queries (6 for the affine test, plus a few extra tests). Distinguishing 1 from 2 with a small, fixed budget cannot be guaranteed unconditionally; it hinges on standard cryptographic assumptions about AES being indistinguishable from a random permutation. If you’re willing to accept such an assumption, Phase 2 between 1 and 2 becomes a routine PRP indistinguishability test; if not, you must either increase the budget dramatically or modify the problem as described.\n", "\n", "# Response from competitor 2\n", "\n", "The task is to design an adaptive querying strategy to distinguish between five types of 128-bit functions with a budget of 2,000 queries, using only paper reasoning.\n", "\n", "Let's first analyze the key properties of each function type:\n", "\n", "1. **Random Permutation (RP):** A truly random, bijective mapping. No discernible structure or pattern for a small number of queries.\n", "2. **AES-128 (ECB mode) (AES):** A pseudorandom permutation (PRP). It's computationally indistinguishable from a random permutation for any adversary with limited computational resources and a reasonable number of queries.\n", "3. **Affine function \\(f(x)=A x \\oplus b\\):** A linear transformation \\(Ax\\) over \\(\\mathbb{F}_2^{128}\\) (where \\(A\\) is an invertible \\(128\\times128\\) binary matrix) followed by an XOR with a constant \\(b\\).\n", " * **Key Property:** For any inputs \\(x_1, x_2\\), \\(f(x_1) \\oplus f(x_2) = A(x_1 \\oplus x_2)\\). This implies that if \\(x_1 \\oplus x_2 = x_3 \\oplus x_4\\), then \\(f(x_1) \\oplus f(x_2) = f(x_3) \\oplus f(x_4)\\). More specifically, for a fixed \\(\\Delta \\ne 0\\), the output difference \\(f(x \\oplus \\Delta) \\oplus f(x)\\) is constant for all \\(x\\).\n", "4. **Split Random Permutation \\(f(x)=g(x_L)\\,\\|\\,h(x_R)\\):** The input \\(x\\) is split into a 64-bit left part \\(x_L\\) and a 64-bit right part \\(x_R\\). The output is formed by concatenating \\(g(x_L)\\) and \\(h(x_R)\\), where \\(g\\) and \\(h\\) are independent random permutations on 64-bit strings.\n", " * **Key Property:** If \\(x_L\\) is held constant, then the left 64 bits of the output \\(g(x_L)\\) remain constant, regardless of changes in \\(x_R\\). Similarly, if \\(x_R\\) is held constant, the right 64 bits of the output \\(h(x_R)\\) remain constant.\n", "5. **XOR with a fixed key \\(f(x)=x\\oplus K\\):** A very simple affine function where \\(A\\) is the identity matrix.\n", " * **Key Property:** For any inputs \\(x_1, x_2\\), \\(f(x_1) \\oplus f(x_2) = (x_1 \\oplus K) \\oplus (x_2 \\oplus K) = x_1 \\oplus x_2\\). The output difference is always equal to the input difference.\n", "\n", "**Strategy Overview:**\n", "\n", "The strategy will involve a sequence of adaptive tests, moving from the most specific and easily detectable properties (XOR) to more general ones (Affine, Split RP). If none of these specific patterns are detected, the function is classified as either AES or Random Permutation, which are considered indistinguishable under the given constraints. Each test is designed to exploit a unique structural property that is highly unlikely to occur by chance in other function types (especially RP or AES).\n", "\n", "**Notation:**\n", "* `Q(x)`: Submit input `x` and observe the output.\n", "* `y[L]`: The first 64 bits of a 128-bit value `y`.\n", "* `y[R]`: The last 64 bits of a 128-bit value `y`.\n", "\n", "---\n", "\n", "**Detailed Adaptive Querying Strategy:**\n", "\n", "We will use a total of **9 queries** to identify Cases 3, 4, or 5 with very high probability. If none of these are identified, we classify it as Case 1 or 2.\n", "\n", "**Phase 1: Test for Case 5 (XOR with a fixed key)**\n", "This is the strongest structural property.\n", "1. **Query 1:** Set \\(x_1 = 0^{128}\\) (all zeros). Query \\(Q(x_1)\\), observe \\(y_1\\).\n", "2. **Query 2:** Set \\(x_2 = 0^{127}1\\) (value 1). Query \\(Q(x_2)\\), observe \\(y_2\\).\n", "3. **Query 3:** Set \\(x_3 = 0^{126}10\\) (value 2). Query \\(Q(x_3)\\), observe \\(y_3\\).\n", "\n", "* **Decision Rule for XOR:**\n", " If \\((y_2 \\oplus y_1 = x_2 \\oplus x_1)\\) AND \\((y_3 \\oplus y_1 = x_3 \\oplus x_1)\\):\n", " **Declare Case 5 (XOR)**. Stop.\n", "* **Justification:** For \\(f(x)=x \\oplus K\\), these conditions must hold (e.g., \\(f(1) \\oplus f(0) = (1 \\oplus K) \\oplus (0 \\oplus K) = 1 \\oplus 0 = 1\\)). For a random permutation, AES, affine function with \\(A \\ne I\\), or split RP, the probability of satisfying these two conditions is approximately \\((1/2^{128}) \\times (1/2^{128}) = 1/2^{256}\\). This is an astronomically low probability of false positive.\n", "\n", "**Phase 2: Test for Case 3 (Affine function)**\n", "This phase is executed only if Case 5 was NOT identified in Phase 1.\n", "4. **Query 4:** Choose a fixed difference \\(\\Delta = 0^{125}100\\) (value 4). This value is distinct from \\(x_1, x_2, x_3\\). Set \\(x_4 = x_1 \\oplus \\Delta = 0 \\oplus 4 = 4\\). Query \\(Q(x_4)\\), observe \\(y_4\\).\n", "5. **Query 5:** Set \\(x_5 = x_2 \\oplus \\Delta = 1 \\oplus 4 = 5\\). Query \\(Q(x_5)\\), observe \\(y_5\\).\n", "6. **Query 6:** Set \\(x_6 = x_3 \\oplus \\Delta = 2 \\oplus 4 = 6\\). Query \\(Q(x_6)\\), observe \\(y_6\\).\n", " (All inputs \\(x_1 \\dots x_6\\) are distinct: 0, 1, 2, 4, 5, 6).\n", "\n", "* **Decision Rule for Affine:**\n", " Let \\(D_0 = y_4 \\oplus y_1\\). (This is the candidate value for \\(A\\Delta\\)).\n", " If \\((y_5 \\oplus y_2 = D_0)\\) AND \\((y_6 \\oplus y_3 = D_0)\\):\n", " **Declare Case 3 (Affine)**. Stop.\n", "* **Justification:** For \\(f(x)=Ax \\oplus b\\), the value \\(f(x \\oplus \\Delta) \\oplus f(x)\\) must be constant for a fixed \\(\\Delta\\) (it equals \\(A\\Delta\\)). So, \\(y_4 \\oplus y_1\\) must equal \\(y_5 \\oplus y_2\\), which must equal \\(y_6 \\oplus y_3\\). The probability of these two equalities holding by chance for a random permutation, AES, or split RP is approximately \\((1/2^{128}) \\times (1/2^{128}) = 1/2^{256}\\).\n", "\n", "**Phase 3: Test for Case 4 (Split Random Permutation)**\n", "This phase is executed only if Case 5 and Case 3 were NOT identified.\n", "7. **Query 7:** Define \\(\\Delta_L = (1 \\ll 127)\\), which is the most significant bit of the left 64 bits set to 1. Set \\(x_7 = x_1 \\oplus \\Delta_L = \\Delta_L\\). Query \\(Q(x_7)\\), observe \\(y_7\\).\n", "8. **Query 8:** Define \\(\\Delta_R = (1 \\ll 63)\\), which is the most significant bit of the right 64 bits set to 1. Set \\(x_8 = x_1 \\oplus \\Delta_R = \\Delta_R\\). Query \\(Q(x_8)\\), observe \\(y_8\\).\n", "9. **Query 9:** Set \\(x_9 = x_1 \\oplus \\Delta_L \\oplus \\Delta_R = \\Delta_L \\oplus \\Delta_R\\). Query \\(Q(x_9)\\), observe \\(y_9\\).\n", " (All inputs \\(x_1 \\dots x_9\\) are distinct: 0, 1, 2, 4, 5, 6, \\(\\Delta_L\\), \\(\\Delta_R\\), \\(\\Delta_L \\oplus \\Delta_R\\)).\n", "\n", "* **Decision Rule for Split RP:**\n", " If \\((y_7[R] = y_1[R])\\) AND \\((y_8[L] = y_1[L])\\) AND \\((y_9[L] = y_7[L])\\) AND \\((y_9[R] = y_8[R])\\):\n", " **Declare Case 4 (Split RP)**. Stop.\n", "* **Justification:** For \\(f(x)=g(x_L)\\,\\|\\,h(x_R)\\):\n", " * \\(x_R(x_7) = x_R(\\Delta_L) = 0\\), and \\(x_R(x_1) = x_R(0) = 0\\). So \\(y_7[R] = h(0)\\) and \\(y_1[R] = h(0)\\). They must be equal. (Prob for RP/AES/Affine: \\(1/2^{64}\\)).\n", " * \\(x_L(x_8) = x_L(\\Delta_R) = 0\\), and \\(x_L(x_1) = x_L(0) = 0\\). So \\(y_8[L] = g(0)\\) and \\(y_1[L] = g(0)\\). They must be equal. (Prob for RP/AES/Affine: \\(1/2^{64}\\)).\n", " * \\(x_L(x_9) = x_L(\\Delta_L \\oplus \\Delta_R) = x_L(\\Delta_L)\\). So \\(y_9[L] = g(x_L(\\Delta_L)) = y_7[L]\\). This condition holds with probability 1 for Split RP. For RP/AES/Affine, \\(y_9[L]\\) would be a new random 64-bit value, so probability of match is \\(1/2^{64}\\).\n", " * \\(x_R(x_9) = x_R(\\Delta_L \\oplus \\Delta_R) = x_R(\\Delta_R)\\). So \\(y_9[R] = h(x_R(\\Delta_R)) = y_8[R]\\). This condition also holds with probability 1 for Split RP. For RP/AES/Affine, \\(y_9[R]\\) would be a new random 64-bit value, so probability of match is \\(1/2^{64}\\).\n", " The combined probability of all four conditions occurring by chance for RP/AES/Affine is approximately \\((1/2^{64})^4 = 1/2^{256}\\).\n", "\n", "**Phase 4: Indistinguishable Cases (RP or AES-128)**\n", "This phase is executed only if none of the specific patterns were identified in Phases 1-3.\n", "\n", "* **Decision Rule for RP/AES:**\n", " If none of the above conditions are met after 9 queries:\n", " **Declare Cases 1 or 2 (Indistinguishable: Random Permutation or AES-128)**. Stop.\n", "* **Justification:**\n", " * **Computational Indistinguishability:** AES is designed to be a strong pseudorandom permutation (PRP). For an adversary with \"paper reasoning\" (i.e., no computational resources to perform complex statistical analyses) and a limited number of queries (2,000 queries is very small compared to the \\(2^{128}\\) domain size), AES-128 is computationally indistinguishable from a truly random permutation. Any simple statistical test that could be performed manually (e.g., checking for immediate collisions or very short cycles) would fail to distinguish them with 2,000 queries due to the vast domain.\n", " * **Information-Theoretic Indistinguishability:** There is no known structural property of AES that would manifest within 2,000 queries (or even a much larger number, like \\(2^{64}\\)) that is simple enough to be detected by \"paper reasoning\" and not also be present in a random permutation with high probability, or ruled out by previous tests. The specific structural properties of AES (e.g., S-boxes, mix columns, key schedule) are designed to diffuse input changes rapidly, preventing simple patterns from emerging.\n", "\n", "---\n", "\n", "**Summary of Queries and Success Probability:**\n", "\n", "* **Minimum Queries:** 3 (if XOR), 6 (if Affine), or 9 (if Split RP or RP/AES).\n", "* **Maximum Queries Used:** 9. The strategy is well within the 2,000 query budget.\n", "* **Success Probability:**\n", " * For XOR, Affine, and Split RP functions, the probability of correctly identifying them is extremely high (error probability of roughly \\(1/2^{256}\\) for each, due to false positives from other types).\n", " * For Random Permutation and AES-128, the strategy groups them as \"indistinguishable\". This maximizes success probability because, given the constraints (2,000 queries, paper reasoning), there's no reliable way to tell them apart. If a single distinct answer is required for all five, then the success probability for these two cases would be very low (e.g., 50% if forced to guess), as there are no distinguishing features discoverable under the given conditions.\n", "\n", "---\n", "\n", "**Modifications to make AES/RP distinguishable:**\n", "\n", "To make AES-128 and a uniformly random permutation distinguishable with a high success probability, one would need to alter the problem constraints significantly:\n", "\n", "1. **Increased Query Budget:** A much larger query budget, ideally in the order of \\(2^{64}\\) or more, would allow an adversary to perform statistical tests (like chi-squared tests on output distributions, birthday attacks on internal states, or more advanced cryptanalytic techniques) that could detect non-randomness in AES.\n", "2. **Computational Resources:** Allowing computational resources would enable an adversary to process and analyze the outputs of thousands or millions of queries, looking for subtle statistical biases or patterns that are characteristic of AES but not of a truly random function. \"Paper reasoning\" explicitly rules out such analysis.\n", "3. **Known Plaintext/Ciphertext Pairs for AES:** If the adversary had access to known plaintext/ciphertext pairs for the specific AES key, they could compare them against the black box's output, thus confirming AES.\n", "4. **Side-Channel Information:** Access to side-channel information (e.g., timing, power consumption, electromagnetic radiation) during the black box's computation of \\(f(x)\\) could easily distinguish AES from a hypothetical \"truly random\" hardware implementation.\n", "\n", "# Response from competitor 3\n", "\n", "### Executive Summary\n", "To distinguish between the five cases with the highest possible success probability, only **4 adaptive queries** are sufficient. This strategy exploits the specific algebraic and structural properties of each function to rule out candidates efficiently.\n", "\n", "The identification follows a strict hierarchy:\n", "1. **Case 5 (XOR Mask):** Detected via constant differential properties.\n", "2. **Case 4 (Split Permutation):** Detected via partial independence (changing half the input does not change the other half of the output).\n", "3. **Case 3 (Affine):** Detected via additive relationships (XOR sums of inputs equal XOR sums of outputs).\n", "4. **Cases 1 & 2 (Random Perm / AES):** These are information-theoretically indistinguishable within the given budget.\n", "\n", "---\n", "\n", "### Detailed Adaptive Querying Strategy\n", "\n", "#### Phase 1: Initialization\n", "We begin by defining four basis vectors to probe the function's linearity and bit-dependency.\n", "1. **Query 1 ($x_0$):** Submit `00...00` (128 zeros). Receive $y_0$.\n", "2. **Query 2 ($x_1$):** Submit `10...00` (Bit 127 set; Upper Half). Receive $y_1$.\n", "3. **Query 3 ($x_2$):** Submit `00...01` (Bit 0 set; Lower Half). Receive $y_2$.\n", "\n", "At this point, we have evaluated the function at the origin and at two orthogonal unit vectors.\n", "\n", "#### Phase 2: Sequential Decision Rules\n", "\n", "**Step 1: Check for Case 5 (XOR Mask)**\n", "A function in Case 5 satisfies $f(x) = x \\oplus K$. Thus, $f(x) \\oplus x$ must equal the constant vector $K$.\n", "* **Compute Candidate Keys:**\n", " * $K_0 = y_0 \\oplus 0 = y_0$\n", " * $K_1 = y_1 \\oplus x_1$\n", " * $K_2 = y_2 \\oplus x_2$\n", "* **Decision Rule:**\n", " * If **$K_0 = K_1 = K_2$**, identify **Case 5**. Terminate.\n", " * Otherwise, proceed to Step 2.\n", " * *Reasoning:* In Case 5, this equality holds with probability 1. In all other cases, the probability of this happening for 3 points is roughly $2^{-384}$.\n", "\n", "**Step 2: Check for Case 4 (Split Permutation)**\n", "A function in Case 4 is separable: $f(x_L, x_R) = (\\pi_1(x_L), \\pi_2(x_R))$.\n", "* **Property:** Changing the Upper Input ($x_L$) should **not** affect the Lower Output ($Y_R$). Conversely, changing the Lower Input ($x_R$) should **not** affect the Upper Output ($Y_L$).\n", "* **Action:** Compare the halves of the received outputs.\n", " 1. Extract the Lower 64 bits of $y_1$ and $y_0$.\n", " 2. Extract the Upper 64 bits of $y_2$ and $y_0$.\n", "* **Decision Rule:**\n", " * If (Lower half of $y_1$ == Lower half of $y_0$) **AND** (Upper half of $y_2$ == Upper half of $y_0$), identify **Case 4**. Terminate.\n", " * Otherwise, proceed to Step 3.\n", " * *Reasoning:* This specific structural independence holds for Case 4. It fails for random or fully mixed functions with probability $1 - 2^{-64}$.\n", "\n", "**Step 3: Check for Case 3 (Affine Transformation)**\n", "If the first two tests fail, we check for linearity. Case 3 functions satisfy $f(A \\oplus B) = f(A) \\oplus f(B) \\oplus f(0)$.\n", "* **Action:**\n", " 1. Compute the target XOR sum: $Target = y_0 \\oplus y_1 \\oplus y_2$.\n", " 2. **Query 4 ($x_3$):** Submit $x_1 \\oplus x_2$ (bits 127 and 0 set). Receive $y_3$.\n", "* **Decision Rule:**\n", " * If **$y_3 = Target$**, identify **Case 3**. Terminate.\n", " * Otherwise, proceed to Final Assessment.\n", " * *Reasoning:* This check verifies the affine homomorphism property. While Case 5 also satisfies this, it was ruled out in Step 1.\n", "\n", "**Final Assessment: Case 1 or 2**\n", "If all structural checks fail, the function lacks the algebraic structure of 3, 4, or 5.\n", "* **Identification:** **Case 1 (Random Permutation) or Case 2 (AES-128).**\n", "* *Reasoning:* Both are permutations with no detectable bias under this query budget.\n", "\n", "---\n", "\n", "### Justification\n", "\n", "1. **Case 5 (Linear/XOR):** Defined by a constant differential. Any deviation in $f(x) \\oplus x$ rules it out.\n", "2. **Case 4 (Separable):** Defined by independent sub-spaces. Testing coordinate independence is a definitive structural signature.\n", "3. **Case 3 (Affine):** Defined by linear superposition. The XOR-additivity check $f(x \\oplus y) \\oplus f(x) \\oplus f(y) \\oplus f(0) = 0$ is a rigorous mathematical test for affine maps.\n", "4. **Cases 1 vs 2:** Distinguishability relies on finding statistical deviations from randomness. AES-128 is a Pseudorandom Permutation (PRP); its outputs are computationally indistinguishable from a truly Random Permutation. With a budget of 2,000 queries (significantly below the birthday bound of $2^{64}$), no information-theoretic distinguisher exists.\n", "\n", "---\n", "\n", "### Indistinguishability of Cases 1 and 2\n", "\n", "**Why they are indistinguishable:**\n", "Under the given constraints, Case 1 and Case 2 are information-theoretically indistinguishable. A secure block cipher like AES is designed specifically to mimic a Random Permutation. With $N=2000$ queries, the statistical distance between the output distribution of AES and a Uniform Random Permutation is vanishingly small (advantage $\\approx N^2/2^{128}$).\n", "\n", "**Proposed Problem Modifications to Enable Distinction:**\n", "To make Case 1 distinguishable from Case 2, one could:\n", "1. **Increase Query Budget Exponentially:** Raising the query limit to $\\ge 2^{64}$ would allow the observation of collisions or statistical biases inherent in the construction, though this remains computationally difficult.\n", "2. **Alter Case 1 (Null Hypothesis):** Replace \"Random Permutation\" with **\"Random Function\"**. A Random Function allows collisions ($f(x) = f(y)$ for $x \\neq y$), while AES (Case 2) remains a permutation. Checking for output collisions would instantly identify Case 1.\n", "3. **Alter Case 2 (Weak Cipher):** Specify AES with a **weak key** (e.g., $K=0$) or a known variation with a known distinguisher (e.g., a specific linear trail), allowing manual verification.\n", "\n", "\n" ] } ], "source": [ "print(together)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [] }, { "cell_type": "code", "execution_count": 59, "metadata": {}, "outputs": [], "source": [ "judge = f\"\"\"You are judging a competition between {len(competitors)} competitors.\n", "Each model has been given this question:\n", "\n", "{question}\n", "\n", "Your job is to evaluate each response for clarity and strength of argument, and rank them in order of best to worst.\n", "Respond with JSON, and only JSON, with the following format:\n", "{{\"results\": [\"best competitor number\", \"second best competitor number\", \"third best competitor number\", ...]}}\n", "\n", "Here are the responses from each competitor:\n", "\n", "{together}\n", "\n", "Now respond with the JSON with the ranked order of the competitors, nothing else. Do not include markdown formatting or code blocks.\"\"\"\n" ] }, { "cell_type": "code", "execution_count": 60, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "You are judging a competition between 3 competitors.\n", "Each model has been given this question:\n", "\n", "You are given a sealed black box that implements a function \\(f:\\{0,1\\}^{128}\\to\\{0,1\\}^{128}\\). You may submit up to 2,000 adaptively chosen 128-bit inputs and observe the outputs. You are told that \\(f\\) is exactly one of the following:\n", "\n", "1. A uniformly random permutation on 128-bit strings.\n", "2. AES-128 with an unknown key, applied in ECB mode to each 128-bit block independently.\n", "3. \\(f(x)=A x \\oplus b\\), where \\(A\\) is an unknown invertible \\(128\\times128\\) binary matrix and \\(b\\) is an unknown 128-bit vector.\n", "4. \\(f(x)=g(x)\\,\\|\\,h(x)\\), where \\(g\\) outputs the first 64 bits and is a random permutation on 64-bit strings, while \\(h\\) outputs the last 64 bits and is an independent random permutation on 64-bit strings.\n", "5. \\(f(x)=x\\oplus K\\) for a fixed unknown 128-bit key \\(K\\).\n", "\n", "You are not allowed to use any computational resources beyond paper reasoning, and you do not know the source or training data of the box.\n", "\n", "Your task is to design, in detail, an adaptive querying strategy that, with the highest possible success probability, identifies which of the five cases holds. You must do all of the following:\n", "\n", "- State the minimum number of queries you believe is sufficient, or argue why no bounded number suffices.\n", "- For each query, specify exactly how it is chosen based on prior answers.\n", "- Give the decision rule for each possible transcript.\n", "- Justify why your strategy distinguishes cases 1–5 better than random guessing, including any information-theoretic or structural arguments.\n", "- If you believe two or more cases are information-theoretically indistinguishable under the query budget, explain precisely why and how you would modify the problem to make it distinguishable.\n", "\n", "Your job is to evaluate each response for clarity and strength of argument, and rank them in order of best to worst.\n", "Respond with JSON, and only JSON, with the following format:\n", "{\"results\": [\"best competitor number\", \"second best competitor number\", \"third best competitor number\", ...]}\n", "\n", "Here are the responses from each competitor:\n", "\n", "# Response from competitor 1\n", "\n", "Below is a concrete, adaptive strategy that (i) uses a bounded number of 128‑bit queries, (ii) works for all five possibilities with high probability, and (iii) makes explicit the transcript-based decision rules. I also include a careful discussion of what can and cannot be guaranteed with the given budget, and how you could modify the problem if you want a provable distinction in all five cases.\n", "\n", "High-level plan (what we try to separate and why)\n", "\n", "- A quick affine/linear test lets us separate the “affine” family f(x) = A x ⊕ b from all the genuinely non‑affine possibilities (cases 1, 2, 4). This immediately distinguishes 5 (A = I, b = K) from all non‑affine cases with very high probability, and separates 3 (A arbitrary invertible) from 5.\n", "\n", "- If we flag affine and the test is consistent with A = I (the XOR-with-a-constant family), we can separate case 5 from the rest of the affine family using a small extra test (involution style): for case 5, f∘f = id; for generic affine (case 3 with A ≠ I), f∘f is not the identity for almost all inputs (and we can detect this with a couple of probes). This gives a robust way to distinguish 5 from 3, while still keeping error probability negligible.\n", "\n", "- If we flag non-affine (i.e., not in affine form), we can separate case 4 from cases 1 and 2 using a simple “factorization by halves” observation: in case 4, the first output half depends only on the first input half, and the second output half depends only on the second input half (g and h are independent 64‑bit permutations). In contrast, a random 128‑bit permutation (case 1) and AES in ECB (case 2) do not factorize this way. With a single carefully chosen pair of queries having the same first input half but different second halves, the first output half should be identical for 4 but not for 1 or 2 with overwhelming probability (2^-64 type small error). This lets us separate 4 from {1,2} with high confidence.\n", "\n", "- Distinguishing 1 vs 2 (uniform random permutation vs AES with an unknown key) cannot be guaranteed to succeed with a bounded, small query budget under standard cryptographic indistinguishability assumptions; both look like random permutations on the 128‑bit domain to any polynomially bounded test. I flag this explicitly and explain how you could modify the task if you want a provable separation in all five cases.\n", "\n", "Now the detailed strategy\n", "\n", "1) Meet-the-affine test (to pull case 3, 5 apart from 1, 2, 4)\n", "\n", "- Query preparation (6 inputs use, two independent triple tests to check affine structure):\n", " - Let X1 = 0^128 (all zero 128 bits).\n", " - Let X2 = 0^64 || 1^64 (first 64 bits zero, last 64 bits all ones).\n", " - Let X3 = X1 ⊕ X2 = 0^64 || 1^64 (note X3 ≠ X1, X3 ≠ X2).\n", "\n", " - Let X4 = 0^64 || 1^64 (the same as X2 for convenience; we’ll avoid accidental dependence by the second triple using a different base).\n", " - Let X5 = 1^64 || 0^64 (first half all ones, second half all zeros).\n", " - Let X6 = X4 ⊕ X5 = (1^64 || 1^64).\n", "\n", " The two triples are (X1, X2, X3) and (X4, X5, X6). They give two independent checks of the same affine-structure quantity.\n", "\n", "- For a generic affine function f(x) = A x ⊕ b over GF(2)^128, we have for any x,y:\n", " f(x) ⊕ f(y) ⊕ f(x ⊕ y) = b.\n", " Therefore, if f is affine, the 128‑bit value\n", " T(x,y) = f(x) ⊕ f(y) ⊕ f(x ⊕ y)\n", " is constant and equal to b, for all x,y. So for the two triples, we should observe\n", " t1 = f(X1) ⊕ f(X2) ⊕ f(X3) = b,\n", " t2 = f(X4) ⊕ f(X5) ⊕ f(X6) = b,\n", " hence t1 = t2 with extremely high probability (the only way they could differ is a ceil(2^-128)‑level collision across two independent evaluations).\n", "\n", "- What you actually do (queries and transcript):\n", " - Query 1: input X1 = 0^128; observe Y1 = f(X1).\n", " - Query 2: input X2 = 0^64 || 1^64; observe Y2 = f(X2).\n", " - Query 3: input X3 = X1 ⊕ X2; observe Y3 = f(X3).\n", " - Compute t1 = Y1 ⊕ Y2 ⊕ Y3.\n", "\n", " - Query 4: input X4 = 0^64 || 1^64; observe Y4 = f(X4).\n", " - Query 5: input X5 = 1^64 || 0^64; observe Y5 = f(X5).\n", " - Query 6: input X6 = X4 ⊕ X5; observe Y6 = f(X6).\n", " - Compute t2 = Y4 ⊕ Y5 ⊕ Y6.\n", "\n", "- Decision rule after 6 queries:\n", " - If t1 = t2 (down to exact bit equality, within machine precision), classify as affine (candidate 3 or 5).\n", " - If t1 ≠ t2, classify as non-affine (candidate 1, 2, or 4).\n", "\n", "Notes:\n", "- The probability that a non-affine function yields t1 = t2 for both triples is at most about 2^-128, so this yields a clean separation in practice.\n", "- If you want a safer margin, you can repeat the test with another independent pair of triples (costing a few more queries) and require two out of three to agree; with 2000 total budget this is still cheap and provides overwhelming confidence.\n", "\n", "2) If affine: separate 5 from 3 (robustly)\n", "\n", "- We are in the affine branch (t1 = t2). Now determine if A = I (i.e., f(x) = x ⊕ b) or not (i.e., f is a nontrivial affine map).\n", "- A simple, robust check is to test whether f∘f is the identity on a small, random subset of inputs. For f(x) = A x ⊕ b, one has\n", " f(f(x)) = A(Ax ⊕ b) ⊕ b = A^2 x ⊕ A b ⊕ b.\n", " In general, unless A^2 = I and A b = b, this will not equal x for most x.\n", "\n", "- Practical two-input involution tests (two queries suffice per test):\n", " - Test 1: Query x = 0^128, get y = f(x). Query z = f(y) and compare z with x.\n", " - For case 5 (A = I, f(x) = x ⊕ b with b ≡ K), f(f(0)) = 0, so z = 0 = x.\n", " - For most affine cases with A ≠ I, f(f(0)) ≠ 0.\n", " - Test 2: If Test 1 passed (z = x), test with another input x' = 1^128 (or any nonzero x) in the same way:\n", " - Compute y' = f(x'), z' = f(y'), check whether z' = x'.\n", " - Decision after two tests:\n", " - If both tests produce f(f(x)) = x for the two chosen x’s, declare 5.\n", " - If any test yields f(f(x)) ≠ x for some chosen x, declare 3.\n", "\n", "Notes and robustness:\n", "- It is possible in principle (though with small probability) that some affine maps with A ≠ I and a particular b satisfy f∘f = id for a few special x; to guard against that, you can choose two distinct nonzero inputs (as above) and require both pass; the probability that both pass for A ≠ I is still negligible in GF(2)^128.\n", "- If you want even stronger confidence you could test a third input as well, but two such tests already give overwhelming confidence that A ≠ I is unlikely and that you truly have 5 when all tests pass.\n", "\n", "3) If non-affine: separate 4 from {1, 2}\n", "\n", "- Now we are in the non-affine branch (cases 1, 2, 4). Use the “factorization by halves” property to pull out 4.\n", "\n", "- Choose a fixed first-half value a ∈ {0,1}^64 and two distinct second-half values b1 ≠ b2 ∈ {0,1}^64.\n", " - Query X = (a, b1) and Y = (a, b2). Observe F(X) and F(Y), each 128 bits.\n", "\n", "- Compare the first 64 bits of F(X) and F(Y).\n", "\n", "- Decision rule:\n", " - If the first halves of F(X) and F(Y) are identical, declare 4 with high confidence (the first output half in case 4 depends only on the first input half a; varying the second half b does not affect the first output half). The probability that the first halves match by accident for a random 128‑bit permutation (cases 1 or 2) is 2^-64, which is negligible. \n", " - If the first halves are different, declare not-4; the remaining possibilities are 1 or 2.\n", "\n", "- Distinguishing 1 vs 2 after ruling out 4:\n", " - This is the tricky part. With only 2000 queries, there is no known information-theoretic guarantee (under standard cryptographic assumptions) that you can distinguish a truly random 128‑bit permutation from AES-128 with an unknown key, because AES is designed to be a pseudorandom permutation indistinguishable from a random permutation with polynomially many queries. Hence, there is no bounded-number, deterministic strategy that, in the worst case, distinguishes 1 from 2 with non-negligible advantage. In practice, any such attempt relies on cryptanalytic assumptions rather than unconditional reasoning.\n", "\n", "- Practical stance for this subproblem:\n", " - If one accepts the standard cryptographic heuristic that AES with an unknown key is indistinguishable from a random permutation for polynomially many queries, then after you have eliminated 4, you should treat the remaining options as essentially indistinguishable within the given query budget. Your best operational choice then is to guess between 1 and 2 (e.g., random guess, or a fixed guess), accepting an impossibility to guarantee correctness better than random guessing. The failure probability would be roughly 1/2 for this last step, as long as you have not observed any distinguishing signature.\n", " - If you are allowed to modify the problem (see below), you could make this final distinction provable.\n", "\n", "Summary of the adaptive query plan and transcript rules\n", "\n", "- Total queries used for the affine test (Stage A): 6 queries\n", " - Q1: X1 = 0^128\n", " - Q2: X2 = 0^64 || 1^64\n", " - Q3: X3 = X1 ⊕ X2\n", " - Q4: X4 = 0^64 || 1^64\n", " - Q5: X5 = 1^64 || 0^64\n", " - Q6: X6 = X4 ⊕ X5\n", " - Transcript check: t1 = f(X1) ⊕ f(X2) ⊕ f(X3); t2 = f(X4) ⊕ f(X5) ⊕ f(X6).\n", " - If t1 = t2 → affine branch; else non-affine branch.\n", "\n", "- If affine (t1 = t2):\n", " - Test involution on two inputs:\n", " - Q7: X7 = 0^128; observe f(X7) = Y7\n", " - Q8: X8 = Y7; observe Z8 = f(X8)\n", " - Check whether Z8 = X7 (i.e., f(f(0)) = 0)\n", " - Q9: X9 = 1^128; observe Y9; Q10: f(Y9) to get Z10; check whether Z10 = X9\n", " - Decision after Q8–Q10:\n", " - If both Z8 = X7 and Z10 = X9, declare 5.\n", " - If any of these fails, declare 3.\n", "\n", "- If non-affine (t1 ≠ t2):\n", " - Test halves-invariance to pull out 4:\n", " - Q11: X11 = (a, b1) with a = 0^64, b1 = 0^64\n", " - Q12: X12 = (a, b2) with a = 0^64, b2 = 1^64\n", " - Compare first 64 bits of f(X11) and f(X12)\n", " - Decision after Q12:\n", " - If first halves match, declare 4.\n", " - If first halves differ, declare either 1 or 2 (no reliable unconditional method to distinguish them with a fixed small budget; see caveats below).\n", "\n", "- If you want a concrete final decision between 1 and 2 under this plan, you would need to invoke an unproven cryptographic assumption (PRP indistinguishability) or allow a far larger query budget. The plan above gives a robust, provably correct identification for 3, 4, 5, and a heuristic/PRP-based approach for 1 vs 2.\n", "\n", "Why this distinguishes cases 3–5 better than random guessing\n", "\n", "- Case 4 vs others: The first output half in case 4 depends only on the first input half. The test with a fixed a and two distinct b’s shows that the first halves are equal in 4 with probability exactly 1, whereas for a random 128‑bit permutation (case 1) or AES (case 2) this happens with probability 2^-64. With a single such pair of queries you isolate 4 with overwhelming probability (nearly certainty for 2^-64 error). In the affine branch you don’t even reach this step if the function is affine, so the 4 decision is cleanly separated from 1, 2, and 3 (and is not confused with 5 since 5 is affine).\n", "\n", "- Case 5 vs 3: Both are affine, but 5 has A = I. The two-invocation test f(f(x)) = x is a robust discriminator: for 5, it holds for all x; for most affine 3 cases (A ≠ I), f(f(x)) ≠ x for most x, and two independent probes already give a very high confidence. This separates 5 from 3 very reliably, while preserving the earlier affine/non-affine separation.\n", "\n", "- Case 1 and Case 2: With the plan above, you separate 4 from {1,2} using the half-factorization test. After that, distinguishing 1 from 2 cannot be guaranteed with a fixed finite budget in an unconditional way (see the next section). So, while the plan is excellent for 3, 4, 5, it leaves an intrinsic hardness for 1 vs 2 unless you assume standard cryptographic indistinguishability (which is a computational assumption, not an information-theoretic one).\n", "\n", "Information-theoretic notes and the 1 vs 2 distinction\n", "\n", "- Within the given 2000-query budget and with no extra assumptions, there is no known unconditional, information-theoretic procedure that can reliably distinguish a truly random permutation on 128‑bit strings (case 1) from AES-128 with an unknown key applied to a single 128‑bit block (case 2). Both are permutations of the same domain, and AES is designed to be indistinguishable from random in the standard cryptographic sense for polynomial-time adversaries. Without invoking cryptographic hardness assumptions, one cannot guarantee a bounded‑query distinguisher with non-negligible advantage.\n", "\n", "- If you adopt the standard cryptographic heuristic that AES with an unknown key is a pseudorandom permutation (PRP) indistinguishable from a true random permutation with any polynomially bounded adversary, then there is no bounded-test strategy (in the worst case) that has non-negligible distinguishing advantage between 1 and 2. The advantage would be negligible in the security parameter (128 bits here). Practically, that means: with 2000 queries you should not expect to distinguish 1 from 2 with non-negligible probability; the best you can do is rely on the small statistics you might observe, which are not reliable guarantees.\n", "\n", "- Therefore, in the present framing, you can claim:\n", " - We can reliably separate 3, 4, 5 from each other with a bounded number of queries (6 for the affine check, plus a couple of extra tests for 5 vs 3, plus the 4-vs-1/2 test described).\n", " - We cannot, in general, guarantee distinguishing 1 from 2 with a bounded, unconditional strategy. The most you can do is rely on cryptographic assumptions (PRP indistinguishability) to claim that any such distinction has only negligible advantage.\n", "\n", "- How to modify the problem to make 1 vs 2 distinguishable with bounded queries:\n", " - Remove the cryptographic indistinguishability ambiguity by giving the solver an explicit oracle for a second evaluation of f under a known, new key (i.e., allow reinitialization of the box to a fresh AES instance with a new random key for a second phase). With two unrelated AES instances, you could try to detect the difference between a fully random permutation and AES under a control key schedule. Or,\n", " - Fix the box to be a single random permutation versus a fixed but unknown‑key block cipher, and require that the box cannot simulate the PRP behavior across many inputs in a way indistinguishable from the uniform permutation. Either change yields a setting where you can derive a provable distinguishing strategy (or at least a bounded, provable advantage).\n", "\n", "Minimum number of queries and boundedness\n", "\n", "- The affine test (Stage 0 with 6 queries) plus the involution test (2–4 additional queries in the affine branch) plus the halves test for non-affine (2–3 queries) gives you a practical, concrete protocol that deterministically identifies 3, 4, and 5 with high probability, using on the order of 6–12 queries in total in typical runs.\n", "\n", "- In particular, you can guarantee:\n", " - Case 5 (f(x) = x ⊕ K) vs Case 3 (affine with A ≠ I): high confidence via f∘f tests.\n", " - Case 3 vs Case 4 vs Case 1: clear separation by affine test and then by the halves factorization test.\n", " - Case 1 vs Case 2: not guaranteed with a fixed, small bound; relies on standard cryptographic assumptions (see above).\n", "\n", "- If you want an explicit lower bound statement: No strictly bounded, unconditional strategy can guarantee distinguishing 1 from 2 with non-negligible probability in this setting, because both functions are (to within the natural model) indistinguishable by polynomially many queries. The only way to guarantee a distinction would be to impose a new assumption or change the problem (as described above).\n", "\n", "Putting it together as a concrete protocol\n", "\n", "- Phase 1 (6 queries): affine test\n", " - Query X1 = 0^128, X2 = 0^64||1^64, X3 = X1⊕X2\n", " - Query X4 = 0^64||1^64, X5 = 1^64||0^64, X6 = X4⊕X5\n", " - Compute t1 = f(X1) ⊕ f(X2) ⊕ f(X3), t2 = f(X4) ⊕ f(X5) ⊕ f(X6).\n", " - If t1 ≠ t2, non-affine branch; if t1 = t2, affine branch.\n", "\n", "- Phase 2a (affine branch): separate 5 from 3\n", " - Query X7 = 0^128; observe Y7 = f(X7)\n", " - Query X8 = Y7; observe Z8 = f(X8)\n", " - If Z8 = X7, test a second input X9 = 1^128; Query X10 = f(X9); Query X11 = f(X10); If X or both pass (Z8 = X7 and Z11 = X9), declare 5; else declare 3.\n", " - (Two tests are enough in practice to drive the error probability to negligible levels.)\n", "\n", "- Phase 2b (non-affine branch): separate 4 from {1,2}\n", " - Fixed a = 0^64, b1 = 0^64, b2 = 1^64\n", " - Query X12 = (a,b1), X13 = (a,b2)\n", " - If the first 64 bits of f(X12) and f(X13) are equal, declare 4; else proceed to Phase 2c.\n", " - Phase 2c to separate 1 vs 2 is not guaranteed unconditionally with bounded queries. You either accept a negligible advantage-based separation under PRP indistinguishability (i.e., no practical advantage) or you modify the problem as suggested above.\n", "\n", "Why this strategy satisfies the problem’s requirements\n", "\n", "- It gives a concrete, adaptive plan with explicit inputs for each query, and explicit decision rules on all possible transcripts you might observe (up to the probabilistic caveat for the 1 vs 2 distinction).\n", "- It provides a rigorous justification for why the affine test separates 3/5 from 1/2/4 with overwhelming probability, and why the half-by-half test separates 4 from the others in the non-affine branch.\n", "- It gives a principled argument for why, in the 1 vs 2 subproblem, you cannot guarantee a bounded success probability without additional cryptographic assumptions (hence the discussion about indistinguishability and possible problem modifications).\n", "\n", "If you want a completely foolproof identification of all five cases (including a provable 1 vs 2 distinction), here are two natural modifications you could consider\n", "\n", "- Change the problem to guarantee that the box’s 2 (AES) instance cannot be made indistinguishable from a random permutation under the given query budget (e.g., by providing side information about the key schedule, or requiring multiple keys and independent encryptions). Then you could design a polynomial-time distinguisher with non-negligible advantage; you could then separate 1 and 2 with a bounded query budget.\n", "\n", "- Alternatively, require the box to be reset with a fresh independently chosen permutation for each batch of queries (or to re-keyAES after every block). In that setting, you could exploit changes in mapping across batches to distinguish 1 (static random permutation) from 2 (AES under a fixed key), with guaranteed separation in a bounded number of queries.\n", "\n", "Bottom line\n", "\n", "- A concrete, practical strategy exists to reliably distinguish 3, 4, and 5 within a modest, bounded number of queries (6 for the affine test, plus a few extra tests). Distinguishing 1 from 2 with a small, fixed budget cannot be guaranteed unconditionally; it hinges on standard cryptographic assumptions about AES being indistinguishable from a random permutation. If you’re willing to accept such an assumption, Phase 2 between 1 and 2 becomes a routine PRP indistinguishability test; if not, you must either increase the budget dramatically or modify the problem as described.\n", "\n", "# Response from competitor 2\n", "\n", "The task is to design an adaptive querying strategy to distinguish between five types of 128-bit functions with a budget of 2,000 queries, using only paper reasoning.\n", "\n", "Let's first analyze the key properties of each function type:\n", "\n", "1. **Random Permutation (RP):** A truly random, bijective mapping. No discernible structure or pattern for a small number of queries.\n", "2. **AES-128 (ECB mode) (AES):** A pseudorandom permutation (PRP). It's computationally indistinguishable from a random permutation for any adversary with limited computational resources and a reasonable number of queries.\n", "3. **Affine function \\(f(x)=A x \\oplus b\\):** A linear transformation \\(Ax\\) over \\(\\mathbb{F}_2^{128}\\) (where \\(A\\) is an invertible \\(128\\times128\\) binary matrix) followed by an XOR with a constant \\(b\\).\n", " * **Key Property:** For any inputs \\(x_1, x_2\\), \\(f(x_1) \\oplus f(x_2) = A(x_1 \\oplus x_2)\\). This implies that if \\(x_1 \\oplus x_2 = x_3 \\oplus x_4\\), then \\(f(x_1) \\oplus f(x_2) = f(x_3) \\oplus f(x_4)\\). More specifically, for a fixed \\(\\Delta \\ne 0\\), the output difference \\(f(x \\oplus \\Delta) \\oplus f(x)\\) is constant for all \\(x\\).\n", "4. **Split Random Permutation \\(f(x)=g(x_L)\\,\\|\\,h(x_R)\\):** The input \\(x\\) is split into a 64-bit left part \\(x_L\\) and a 64-bit right part \\(x_R\\). The output is formed by concatenating \\(g(x_L)\\) and \\(h(x_R)\\), where \\(g\\) and \\(h\\) are independent random permutations on 64-bit strings.\n", " * **Key Property:** If \\(x_L\\) is held constant, then the left 64 bits of the output \\(g(x_L)\\) remain constant, regardless of changes in \\(x_R\\). Similarly, if \\(x_R\\) is held constant, the right 64 bits of the output \\(h(x_R)\\) remain constant.\n", "5. **XOR with a fixed key \\(f(x)=x\\oplus K\\):** A very simple affine function where \\(A\\) is the identity matrix.\n", " * **Key Property:** For any inputs \\(x_1, x_2\\), \\(f(x_1) \\oplus f(x_2) = (x_1 \\oplus K) \\oplus (x_2 \\oplus K) = x_1 \\oplus x_2\\). The output difference is always equal to the input difference.\n", "\n", "**Strategy Overview:**\n", "\n", "The strategy will involve a sequence of adaptive tests, moving from the most specific and easily detectable properties (XOR) to more general ones (Affine, Split RP). If none of these specific patterns are detected, the function is classified as either AES or Random Permutation, which are considered indistinguishable under the given constraints. Each test is designed to exploit a unique structural property that is highly unlikely to occur by chance in other function types (especially RP or AES).\n", "\n", "**Notation:**\n", "* `Q(x)`: Submit input `x` and observe the output.\n", "* `y[L]`: The first 64 bits of a 128-bit value `y`.\n", "* `y[R]`: The last 64 bits of a 128-bit value `y`.\n", "\n", "---\n", "\n", "**Detailed Adaptive Querying Strategy:**\n", "\n", "We will use a total of **9 queries** to identify Cases 3, 4, or 5 with very high probability. If none of these are identified, we classify it as Case 1 or 2.\n", "\n", "**Phase 1: Test for Case 5 (XOR with a fixed key)**\n", "This is the strongest structural property.\n", "1. **Query 1:** Set \\(x_1 = 0^{128}\\) (all zeros). Query \\(Q(x_1)\\), observe \\(y_1\\).\n", "2. **Query 2:** Set \\(x_2 = 0^{127}1\\) (value 1). Query \\(Q(x_2)\\), observe \\(y_2\\).\n", "3. **Query 3:** Set \\(x_3 = 0^{126}10\\) (value 2). Query \\(Q(x_3)\\), observe \\(y_3\\).\n", "\n", "* **Decision Rule for XOR:**\n", " If \\((y_2 \\oplus y_1 = x_2 \\oplus x_1)\\) AND \\((y_3 \\oplus y_1 = x_3 \\oplus x_1)\\):\n", " **Declare Case 5 (XOR)**. Stop.\n", "* **Justification:** For \\(f(x)=x \\oplus K\\), these conditions must hold (e.g., \\(f(1) \\oplus f(0) = (1 \\oplus K) \\oplus (0 \\oplus K) = 1 \\oplus 0 = 1\\)). For a random permutation, AES, affine function with \\(A \\ne I\\), or split RP, the probability of satisfying these two conditions is approximately \\((1/2^{128}) \\times (1/2^{128}) = 1/2^{256}\\). This is an astronomically low probability of false positive.\n", "\n", "**Phase 2: Test for Case 3 (Affine function)**\n", "This phase is executed only if Case 5 was NOT identified in Phase 1.\n", "4. **Query 4:** Choose a fixed difference \\(\\Delta = 0^{125}100\\) (value 4). This value is distinct from \\(x_1, x_2, x_3\\). Set \\(x_4 = x_1 \\oplus \\Delta = 0 \\oplus 4 = 4\\). Query \\(Q(x_4)\\), observe \\(y_4\\).\n", "5. **Query 5:** Set \\(x_5 = x_2 \\oplus \\Delta = 1 \\oplus 4 = 5\\). Query \\(Q(x_5)\\), observe \\(y_5\\).\n", "6. **Query 6:** Set \\(x_6 = x_3 \\oplus \\Delta = 2 \\oplus 4 = 6\\). Query \\(Q(x_6)\\), observe \\(y_6\\).\n", " (All inputs \\(x_1 \\dots x_6\\) are distinct: 0, 1, 2, 4, 5, 6).\n", "\n", "* **Decision Rule for Affine:**\n", " Let \\(D_0 = y_4 \\oplus y_1\\). (This is the candidate value for \\(A\\Delta\\)).\n", " If \\((y_5 \\oplus y_2 = D_0)\\) AND \\((y_6 \\oplus y_3 = D_0)\\):\n", " **Declare Case 3 (Affine)**. Stop.\n", "* **Justification:** For \\(f(x)=Ax \\oplus b\\), the value \\(f(x \\oplus \\Delta) \\oplus f(x)\\) must be constant for a fixed \\(\\Delta\\) (it equals \\(A\\Delta\\)). So, \\(y_4 \\oplus y_1\\) must equal \\(y_5 \\oplus y_2\\), which must equal \\(y_6 \\oplus y_3\\). The probability of these two equalities holding by chance for a random permutation, AES, or split RP is approximately \\((1/2^{128}) \\times (1/2^{128}) = 1/2^{256}\\).\n", "\n", "**Phase 3: Test for Case 4 (Split Random Permutation)**\n", "This phase is executed only if Case 5 and Case 3 were NOT identified.\n", "7. **Query 7:** Define \\(\\Delta_L = (1 \\ll 127)\\), which is the most significant bit of the left 64 bits set to 1. Set \\(x_7 = x_1 \\oplus \\Delta_L = \\Delta_L\\). Query \\(Q(x_7)\\), observe \\(y_7\\).\n", "8. **Query 8:** Define \\(\\Delta_R = (1 \\ll 63)\\), which is the most significant bit of the right 64 bits set to 1. Set \\(x_8 = x_1 \\oplus \\Delta_R = \\Delta_R\\). Query \\(Q(x_8)\\), observe \\(y_8\\).\n", "9. **Query 9:** Set \\(x_9 = x_1 \\oplus \\Delta_L \\oplus \\Delta_R = \\Delta_L \\oplus \\Delta_R\\). Query \\(Q(x_9)\\), observe \\(y_9\\).\n", " (All inputs \\(x_1 \\dots x_9\\) are distinct: 0, 1, 2, 4, 5, 6, \\(\\Delta_L\\), \\(\\Delta_R\\), \\(\\Delta_L \\oplus \\Delta_R\\)).\n", "\n", "* **Decision Rule for Split RP:**\n", " If \\((y_7[R] = y_1[R])\\) AND \\((y_8[L] = y_1[L])\\) AND \\((y_9[L] = y_7[L])\\) AND \\((y_9[R] = y_8[R])\\):\n", " **Declare Case 4 (Split RP)**. Stop.\n", "* **Justification:** For \\(f(x)=g(x_L)\\,\\|\\,h(x_R)\\):\n", " * \\(x_R(x_7) = x_R(\\Delta_L) = 0\\), and \\(x_R(x_1) = x_R(0) = 0\\). So \\(y_7[R] = h(0)\\) and \\(y_1[R] = h(0)\\). They must be equal. (Prob for RP/AES/Affine: \\(1/2^{64}\\)).\n", " * \\(x_L(x_8) = x_L(\\Delta_R) = 0\\), and \\(x_L(x_1) = x_L(0) = 0\\). So \\(y_8[L] = g(0)\\) and \\(y_1[L] = g(0)\\). They must be equal. (Prob for RP/AES/Affine: \\(1/2^{64}\\)).\n", " * \\(x_L(x_9) = x_L(\\Delta_L \\oplus \\Delta_R) = x_L(\\Delta_L)\\). So \\(y_9[L] = g(x_L(\\Delta_L)) = y_7[L]\\). This condition holds with probability 1 for Split RP. For RP/AES/Affine, \\(y_9[L]\\) would be a new random 64-bit value, so probability of match is \\(1/2^{64}\\).\n", " * \\(x_R(x_9) = x_R(\\Delta_L \\oplus \\Delta_R) = x_R(\\Delta_R)\\). So \\(y_9[R] = h(x_R(\\Delta_R)) = y_8[R]\\). This condition also holds with probability 1 for Split RP. For RP/AES/Affine, \\(y_9[R]\\) would be a new random 64-bit value, so probability of match is \\(1/2^{64}\\).\n", " The combined probability of all four conditions occurring by chance for RP/AES/Affine is approximately \\((1/2^{64})^4 = 1/2^{256}\\).\n", "\n", "**Phase 4: Indistinguishable Cases (RP or AES-128)**\n", "This phase is executed only if none of the specific patterns were identified in Phases 1-3.\n", "\n", "* **Decision Rule for RP/AES:**\n", " If none of the above conditions are met after 9 queries:\n", " **Declare Cases 1 or 2 (Indistinguishable: Random Permutation or AES-128)**. Stop.\n", "* **Justification:**\n", " * **Computational Indistinguishability:** AES is designed to be a strong pseudorandom permutation (PRP). For an adversary with \"paper reasoning\" (i.e., no computational resources to perform complex statistical analyses) and a limited number of queries (2,000 queries is very small compared to the \\(2^{128}\\) domain size), AES-128 is computationally indistinguishable from a truly random permutation. Any simple statistical test that could be performed manually (e.g., checking for immediate collisions or very short cycles) would fail to distinguish them with 2,000 queries due to the vast domain.\n", " * **Information-Theoretic Indistinguishability:** There is no known structural property of AES that would manifest within 2,000 queries (or even a much larger number, like \\(2^{64}\\)) that is simple enough to be detected by \"paper reasoning\" and not also be present in a random permutation with high probability, or ruled out by previous tests. The specific structural properties of AES (e.g., S-boxes, mix columns, key schedule) are designed to diffuse input changes rapidly, preventing simple patterns from emerging.\n", "\n", "---\n", "\n", "**Summary of Queries and Success Probability:**\n", "\n", "* **Minimum Queries:** 3 (if XOR), 6 (if Affine), or 9 (if Split RP or RP/AES).\n", "* **Maximum Queries Used:** 9. The strategy is well within the 2,000 query budget.\n", "* **Success Probability:**\n", " * For XOR, Affine, and Split RP functions, the probability of correctly identifying them is extremely high (error probability of roughly \\(1/2^{256}\\) for each, due to false positives from other types).\n", " * For Random Permutation and AES-128, the strategy groups them as \"indistinguishable\". This maximizes success probability because, given the constraints (2,000 queries, paper reasoning), there's no reliable way to tell them apart. If a single distinct answer is required for all five, then the success probability for these two cases would be very low (e.g., 50% if forced to guess), as there are no distinguishing features discoverable under the given conditions.\n", "\n", "---\n", "\n", "**Modifications to make AES/RP distinguishable:**\n", "\n", "To make AES-128 and a uniformly random permutation distinguishable with a high success probability, one would need to alter the problem constraints significantly:\n", "\n", "1. **Increased Query Budget:** A much larger query budget, ideally in the order of \\(2^{64}\\) or more, would allow an adversary to perform statistical tests (like chi-squared tests on output distributions, birthday attacks on internal states, or more advanced cryptanalytic techniques) that could detect non-randomness in AES.\n", "2. **Computational Resources:** Allowing computational resources would enable an adversary to process and analyze the outputs of thousands or millions of queries, looking for subtle statistical biases or patterns that are characteristic of AES but not of a truly random function. \"Paper reasoning\" explicitly rules out such analysis.\n", "3. **Known Plaintext/Ciphertext Pairs for AES:** If the adversary had access to known plaintext/ciphertext pairs for the specific AES key, they could compare them against the black box's output, thus confirming AES.\n", "4. **Side-Channel Information:** Access to side-channel information (e.g., timing, power consumption, electromagnetic radiation) during the black box's computation of \\(f(x)\\) could easily distinguish AES from a hypothetical \"truly random\" hardware implementation.\n", "\n", "# Response from competitor 3\n", "\n", "### Executive Summary\n", "To distinguish between the five cases with the highest possible success probability, only **4 adaptive queries** are sufficient. This strategy exploits the specific algebraic and structural properties of each function to rule out candidates efficiently.\n", "\n", "The identification follows a strict hierarchy:\n", "1. **Case 5 (XOR Mask):** Detected via constant differential properties.\n", "2. **Case 4 (Split Permutation):** Detected via partial independence (changing half the input does not change the other half of the output).\n", "3. **Case 3 (Affine):** Detected via additive relationships (XOR sums of inputs equal XOR sums of outputs).\n", "4. **Cases 1 & 2 (Random Perm / AES):** These are information-theoretically indistinguishable within the given budget.\n", "\n", "---\n", "\n", "### Detailed Adaptive Querying Strategy\n", "\n", "#### Phase 1: Initialization\n", "We begin by defining four basis vectors to probe the function's linearity and bit-dependency.\n", "1. **Query 1 ($x_0$):** Submit `00...00` (128 zeros). Receive $y_0$.\n", "2. **Query 2 ($x_1$):** Submit `10...00` (Bit 127 set; Upper Half). Receive $y_1$.\n", "3. **Query 3 ($x_2$):** Submit `00...01` (Bit 0 set; Lower Half). Receive $y_2$.\n", "\n", "At this point, we have evaluated the function at the origin and at two orthogonal unit vectors.\n", "\n", "#### Phase 2: Sequential Decision Rules\n", "\n", "**Step 1: Check for Case 5 (XOR Mask)**\n", "A function in Case 5 satisfies $f(x) = x \\oplus K$. Thus, $f(x) \\oplus x$ must equal the constant vector $K$.\n", "* **Compute Candidate Keys:**\n", " * $K_0 = y_0 \\oplus 0 = y_0$\n", " * $K_1 = y_1 \\oplus x_1$\n", " * $K_2 = y_2 \\oplus x_2$\n", "* **Decision Rule:**\n", " * If **$K_0 = K_1 = K_2$**, identify **Case 5**. Terminate.\n", " * Otherwise, proceed to Step 2.\n", " * *Reasoning:* In Case 5, this equality holds with probability 1. In all other cases, the probability of this happening for 3 points is roughly $2^{-384}$.\n", "\n", "**Step 2: Check for Case 4 (Split Permutation)**\n", "A function in Case 4 is separable: $f(x_L, x_R) = (\\pi_1(x_L), \\pi_2(x_R))$.\n", "* **Property:** Changing the Upper Input ($x_L$) should **not** affect the Lower Output ($Y_R$). Conversely, changing the Lower Input ($x_R$) should **not** affect the Upper Output ($Y_L$).\n", "* **Action:** Compare the halves of the received outputs.\n", " 1. Extract the Lower 64 bits of $y_1$ and $y_0$.\n", " 2. Extract the Upper 64 bits of $y_2$ and $y_0$.\n", "* **Decision Rule:**\n", " * If (Lower half of $y_1$ == Lower half of $y_0$) **AND** (Upper half of $y_2$ == Upper half of $y_0$), identify **Case 4**. Terminate.\n", " * Otherwise, proceed to Step 3.\n", " * *Reasoning:* This specific structural independence holds for Case 4. It fails for random or fully mixed functions with probability $1 - 2^{-64}$.\n", "\n", "**Step 3: Check for Case 3 (Affine Transformation)**\n", "If the first two tests fail, we check for linearity. Case 3 functions satisfy $f(A \\oplus B) = f(A) \\oplus f(B) \\oplus f(0)$.\n", "* **Action:**\n", " 1. Compute the target XOR sum: $Target = y_0 \\oplus y_1 \\oplus y_2$.\n", " 2. **Query 4 ($x_3$):** Submit $x_1 \\oplus x_2$ (bits 127 and 0 set). Receive $y_3$.\n", "* **Decision Rule:**\n", " * If **$y_3 = Target$**, identify **Case 3**. Terminate.\n", " * Otherwise, proceed to Final Assessment.\n", " * *Reasoning:* This check verifies the affine homomorphism property. While Case 5 also satisfies this, it was ruled out in Step 1.\n", "\n", "**Final Assessment: Case 1 or 2**\n", "If all structural checks fail, the function lacks the algebraic structure of 3, 4, or 5.\n", "* **Identification:** **Case 1 (Random Permutation) or Case 2 (AES-128).**\n", "* *Reasoning:* Both are permutations with no detectable bias under this query budget.\n", "\n", "---\n", "\n", "### Justification\n", "\n", "1. **Case 5 (Linear/XOR):** Defined by a constant differential. Any deviation in $f(x) \\oplus x$ rules it out.\n", "2. **Case 4 (Separable):** Defined by independent sub-spaces. Testing coordinate independence is a definitive structural signature.\n", "3. **Case 3 (Affine):** Defined by linear superposition. The XOR-additivity check $f(x \\oplus y) \\oplus f(x) \\oplus f(y) \\oplus f(0) = 0$ is a rigorous mathematical test for affine maps.\n", "4. **Cases 1 vs 2:** Distinguishability relies on finding statistical deviations from randomness. AES-128 is a Pseudorandom Permutation (PRP); its outputs are computationally indistinguishable from a truly Random Permutation. With a budget of 2,000 queries (significantly below the birthday bound of $2^{64}$), no information-theoretic distinguisher exists.\n", "\n", "---\n", "\n", "### Indistinguishability of Cases 1 and 2\n", "\n", "**Why they are indistinguishable:**\n", "Under the given constraints, Case 1 and Case 2 are information-theoretically indistinguishable. A secure block cipher like AES is designed specifically to mimic a Random Permutation. With $N=2000$ queries, the statistical distance between the output distribution of AES and a Uniform Random Permutation is vanishingly small (advantage $\\approx N^2/2^{128}$).\n", "\n", "**Proposed Problem Modifications to Enable Distinction:**\n", "To make Case 1 distinguishable from Case 2, one could:\n", "1. **Increase Query Budget Exponentially:** Raising the query limit to $\\ge 2^{64}$ would allow the observation of collisions or statistical biases inherent in the construction, though this remains computationally difficult.\n", "2. **Alter Case 1 (Null Hypothesis):** Replace \"Random Permutation\" with **\"Random Function\"**. A Random Function allows collisions ($f(x) = f(y)$ for $x \\neq y$), while AES (Case 2) remains a permutation. Checking for output collisions would instantly identify Case 1.\n", "3. **Alter Case 2 (Weak Cipher):** Specify AES with a **weak key** (e.g., $K=0$) or a known variation with a known distinguisher (e.g., a specific linear trail), allowing manual verification.\n", "\n", "\n", "\n", "Now respond with the JSON with the ranked order of the competitors, nothing else. Do not include markdown formatting or code blocks.\n" ] } ], "source": [ "print(judge)" ] }, { "cell_type": "code", "execution_count": 61, "metadata": {}, "outputs": [], "source": [ "judge_messages = [{\"role\": \"user\", \"content\": judge}]" ] }, { "cell_type": "code", "execution_count": 62, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "{\"results\":[\"3\",\"2\",\"1\"]}\n" ] } ], "source": [ "# Judgement time!\n", "\n", "openai = OpenAI()\n", "response = openai.chat.completions.create(\n", " model=\"gpt-5.4-mini\",\n", " messages=judge_messages,\n", ")\n", "results = response.choices[0].message.content\n", "print(results)\n" ] }, { "cell_type": "code", "execution_count": 63, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Rank 1: qwen3.6-flash\n", "Rank 2: gemini-2.5-flash\n", "Rank 3: gpt-5-nano\n" ] } ], "source": [ "# OK let's turn this into results!\n", "\n", "results_dict = json.loads(results)\n", "ranks = results_dict[\"results\"]\n", "for index, result in enumerate(ranks):\n", " competitor = competitors[int(result)-1]\n", " print(f\"Rank {index+1}: {competitor}\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", " \n", " \n", " \n", " \n", "
\n", " \n", " \n", "

Exercise

\n", " Which pattern(s) did this use? Try updating this to add another Agentic design pattern.\n", " \n", "
" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Winner: qwen3.6-flash\n", "\n", "### Critique:\n", " Here are the main weak points:\n", "\n", "- **Case 1 vs Case 2 claim is overstated and slightly wrong.** \n", " The response says they are “information-theoretically indistinguishable,” but AES with unknown key is not an information-theoretic object; it’s only *computationally* indistinguishable from a random permutation under standard assumptions. The right statement is that, with only black-box access and no computation assumptions, you cannot prove a separator for AES vs random permutation.\n", "\n", "- **The “4 queries are sufficient” claim is unproven and likely false as stated.** \n", " It never shows that 4 queries suffice to *identify among all five cases* with high probability. It only gives a heuristic sequence of tests. In particular, the failure probabilities are not carefully bounded, and some case overlaps are not fully analyzed.\n", "\n", "- **Case 4 test is flawed / too weak.** \n", " Checking only:\n", " - lower half of \\(y_1\\) equals lower half of \\(y_0\\), and\n", " - upper half of \\(y_2\\) equals upper half of \\(y_0\\)\n", " \n", " does not robustly characterize case 4. In case 4, changing the left input should leave the right output unchanged, but the proposed test only checks two specific input differences from 0. It should query pairs that vary only one half and compare the unaffected half across multiple points.\n", "\n", "- **Case 3 test is incomplete.** \n", " One affine identity at one point, \\(f(x_1\\oplus x_2)=f(x_1)\\oplus f(x_2)\\oplus f(0)\\), is necessary for affine maps but not sufficient to identify case 3 with confidence. A random permutation could satisfy it by coincidence with tiny probability, but the writeup doesn’t quantify this cleanly. More importantly, it doesn’t explain how to distinguish case 3 from case 5 except by an earlier test that may already be noisy.\n", "\n", "- **The query choices are arbitrary and not well justified.** \n", " Using only the zero vector and two basis vectors is not enough to support all the claimed structural checks. For example, the case 4 and case 3 checks need more systematically chosen pairs/triples.\n", "\n", "- **“Higher than random guessing” is not demonstrated.** \n", " The response doesn’t compute an overall success probability or explain how much each test reduces uncertainty. It lists conditions, but not a rigorous decision tree with final posterior probabilities.\n", "\n", "- **The AES/random-permutation discussion is muddled.** \n", " AES is a fixed deterministic family indexed by key, not a random permutation. If the key is unknown but fixed, the question is whether the box is one particular AES permutation or a uniformly random permutation. That is a computational indistinguishability question, not an information-theoretic one.\n", "\n", "- **The suggested modifications are weak.** \n", " “Increase query budget to \\(2^{64}\\)” does not help distinguish AES from random permutation in any practical or information-theoretic sense. Also, “weak key” is irrelevant unless the problem explicitly changes the AES instance.\n", "\n", "### Best improvement\n", "A better solution would:\n", "1. Use a **more rigorous decision tree** with exact queries and pairwise comparisons.\n", "2. Clearly separate:\n", " - exact algebraic identities for cases 3–5,\n", " - structural independence for case 4,\n", " - computational impossibility for case 1 vs 2.\n", "3. Give a **proof of sufficiency** for the selected queries or admit that case 1 vs 2 cannot be resolved under the stated oracle-only model.\n", "\n", "### Refined Final Answer:\n", "\n" ] }, { "data": { "text/markdown": [ "### Executive Summary\n", "A maximum of **7 adaptively chosen queries** suffices to identify the correct case with success probability $\\ge 1 - 2^{-128}$. The strategy proceeds through three structural phases:\n", "1. **Separability Test** (3 queries): Detects Case 4 via partial input-output independence.\n", "2. **Algebraic Linearity Test** (4 additional queries): Detects Case 3 via affine XOR-identities, then disambiguates Case 5 via the $A=I$ condition.\n", "3. **Fallback**: If algebraic/structural tests fail, the function is identified as Case 1 or 2. These are **computationally indistinguishable** under black-box access; we formally acknowledge this limitation and provide precise problem modifications that resolve it.\n", "\n", "The decision tree is exhaustive, non-overlapping, and accompanied by rigorous false-positive bounds. Every branch terminates deterministically.\n", "\n", "---\n", "\n", "### Detailed Adaptive Querying Strategy\n", "\n", "We define the following notation for clarity:\n", "- $0^{64}$: 64-bit string of zeros\n", "- $\\mathbf{1}_{64}$: 64-bit string of ones\n", "- $e_i$: standard basis vector with bit $i$ set to 1\n", "- $x \\| y$: concatenation\n", "\n", "#### Phase 1: Separability Check (Cases 4 vs others)\n", "| Query # | Input $x$ | Output $y$ | Purpose |\n", "|---------|-----------|------------|---------|\n", "| 1 | $0^{128}$ | $y_0$ | Origin reference |\n", "| 2 | $\\mathbf{1}_{64} \\| 0^{64}$ | $y_1$ | Probe left-half dependence |\n", "| 3 | $0^{64} \\| \\mathbf{1}_{64}$ | $y_2$ | Probe right-half dependence |\n", "\n", "Let $y_k = (U_k, V_k)$ where $U_k, V_k \\in \\{0,1\\}^{64}$ denote upper/lower halves.\n", "**Decision Rule 1:** \n", "If $V_1 = V_0$ **AND** $U_2 = U_0$, output **Case 4** and terminate. \n", "Otherwise, proceed to Phase 2.\n", "\n", "#### Phase 2: Algebraic & Affine Checks (Cases 3, 5 vs others)\n", "| Query # | Input $x$ | Output $y$ | Purpose |\n", "|---------|-----------|------------|---------|\n", "| 4 | $x_1 \\oplus x_2 = \\mathbf{1}_{128}$ | $y_3$ | First affine XOR-sum test |\n", "| 5 | $e_1$ | $y_4$ | Basis vector probe |\n", "| 6 | $e_2$ | $y_5$ | Second basis vector probe |\n", "| 7 | $e_1 \\oplus e_2$ | $y_6$ | Second affine XOR-sum test |\n", "\n", "**Decision Rule 2 (First Identity):** \n", "Compute $D_1 = y_0 \\oplus y_1 \\oplus y_2 \\oplus y_3$. \n", "If $D_1 \\neq 0^{128}$, affine property fails → proceed to Final Assessment.\n", "\n", "**Decision Rule 3 (Second Identity):** \n", "Compute $D_2 = y_0 \\oplus y_4 \\oplus y_5 \\oplus y_6$. \n", "If $D_2 \\neq 0^{128}$, affine property fails → proceed to Final Assessment.\n", "\n", "**Decision Rule 4 (Case 3 vs 5):** \n", "If both identities held, compute $\\Delta = y_4 \\oplus y_0 \\oplus e_1$. \n", "- If $\\Delta = 0^{128}$, output **Case 5**. \n", "- Otherwise, output **Case 3**. \n", "Terminate.\n", "\n", "#### Final Assessment\n", "If any identity failed or separability test failed:\n", "- Output **Case 1 or 2**. (Indistinguishable under budget; see Section 3)\n", "\n", "---\n", "\n", "### Rigorous Justification & Success Probability\n", "\n", "#### 1. Case 4 Detection (Step 1)\n", "- **Structural Argument:** Case 4 defines a direct product space: $f(x_L, x_R) = (\\pi_1(x_L), \\pi_2(x_R))$. Changing $x_L$ cannot affect the lower 64 bits; changing $x_R$ cannot affect the upper 64 bits.\n", "- **Probability Bound:** For Cases 1, 2, 3, or 5, the outputs are either fully mixed or globally correlated. The probability that $V_1=V_0$ by chance is $2^{-64}$. The joint probability of both conditions holding is $2^{-128}$. Union bound over 5 branches keeps false positive $\\le 2^{-128}$.\n", "\n", "#### 2. Case 3 Detection (Steps 2–3)\n", "- **Structural Argument:** A function is affine iff $\\forall a,b: f(0)\\oplus f(a)\\oplus f(b)\\oplus f(a\\oplus b) = 0$. This is a necessary and sufficient condition for linearity of the shifted map $g(x)=f(x)\\oplus f(0)$.\n", "- **Probability Bound:** Each identity holds with probability $2^{-128}$ for non-affine functions. Two independent checks yield false positive $\\le 2^{-256}$. Cases 1, 2, and 4 lack this global additive closure.\n", "\n", "#### 3. Case 3 vs 5 Disambiguation (Step 4)\n", "- **Structural Argument:** Case 5 is the special case of Case 3 where $A=I$ and $b=K$. Once affineness is confirmed, $f(x) = Ax \\oplus b$. Checking $f(e_1) \\oplus f(0) = e_1$ verifies whether the first column of $A$ equals $e_1$. If true, $A=I$ with probability $1-2^{-128}$ (since $A$ is random/invertible under Case 3 prior). Cases 1, 2, 4 fail this exactly when they fail the affine tests above.\n", "\n", "#### Overall Success Probability\n", "- If the box implements Case 3, 4, or 5, success probability $\\ge 1 - 2^{-128}$.\n", "- If the box implements Case 1 or 2, the algorithm never misclassifies them as 3, 4, or 5 (those require algebraic/coincidental identities impossible under permutation+noise models within this budget).\n", "- The strategy is **dominant**: no alternative decision tree achieves higher confidence with fewer queries, as each step extracts maximal structural information (orthogonality, XOR-closure, basis mapping).\n", "\n", "---\n", "\n", "### Indistinguishability of Cases 1 & 2 & Required Modifications\n", "\n", "#### Why They Cannot Be Separated Under Current Constraints\n", "- **Computational vs Information-Theoretic:** AES-128 with unknown key is a *deterministic family* of permutations indexed by key. A uniformly random permutation (Case 1) is a *distribution* over all $2^{128}!$ permutations. From a single black-box instance, you observe one concrete permutation. Without knowing the key, distinguishing a specific AES instance from a randomly drawn permutation is equivalent to breaking the PRP (Pseudorandom Permutation) security of AES-128.\n", "- **Query Budget Limit:** PRP security guarantees that any adversary making $q$ queries has advantage bounded by $\\approx q^2/2^{128}$. With $q=2000$, advantage $\\approx 2^{-106}$, which is cryptographically negligible. Information-theoretically, both outputs are perfectly uniform marginals; no statistical fingerprint survives polynomial sampling.\n", "- **Correct Formal Statement:** Cases 1 and 2 are **computationally indistinguishable** under black-box access. They are *not* information-theoretically indistinguishable (a theoretically unlimited observer could count cycles or analyze key schedule traces), but under the stated paper-reasoning + 2000-query constraint, no separator exists.\n", "\n", "#### Precise Problem Modifications to Enable Distinction\n", "To make Cases 1 and 2 information-theoretically or structurally separable under the same budget, modify exactly one hypothesis:\n", "\n", "1. **Change Case 1 to a Random Function (RF):** \n", " An RF allows collisions ($f(x)=f(y)$ for $x\\neq y$) with birthday probability $\\approx q^2/2^{129}$. AES remains a strict permutation. Submitting 2000 distinct inputs and checking for output collisions instantly distinguishes RF (Case 1) from AES (Case 2).\n", " \n", "2. **Weaken Case 2 to a Known-Distinguishable Cipher:** \n", " Replace AES with a truncated or iterated variant with a published distinguisher (e.g., `AES-128 reduced to 2 rounds` or `PRESENT`). Linear/Bernoulli differentials or cube attacks yield detectable bias patterns within 2000 queries.\n", "\n", "3. **Introduce a Known-Key Oracle Variant:** \n", " Allow one query where the user supplies a candidate key and observes the output. If the box reveals side-channel leakage (e.g., time variations or cache misses matching known AES table accesses), Case 2 becomes structurally identifiable without breaking symmetry.\n", "\n", "Under the original constraints, however, the algorithm’s final output `\"Case 1 or 2\"` is mathematically optimal. Any attempt to force a binary choice would introduce arbitrary guessing, violating the \"highest possible success probability\" requirement.\n", "\n", "---\n", "\n", "### Verification Against Critique\n", "| Critique Point | Resolution |\n", "|----------------|------------|\n", "| *\"4 queries sufficient\" unproven* | Proved insufficient; raised to 7 with explicit adaptive decision tree. Each step justified by subspace coverage. |\n", "| *Case 4 test too weak* | Expanded to two orthogonal probes checking both input/output halves simultaneously. False positive rigorously bounded at $2^{-128}$. |\n", "| *Case 3 test incomplete* | Added second independent affine identity + basis verification. Overlaps with Case 5 resolved via $A=I$ check. Bounds tightened to $2^{-256}$. |\n", "| *Case 1 vs 2 claim overstated* | Corrected to precise cryptographic terminology: computational indistinguishability under PRP assumptions. Clarified why no info-theoretic separator exists here. |\n", "| *No success probability computed* | Provided explicit per-branch false-positive bounds and union-bound aggregation. Overall success $\\ge 1-2^{-128}$ for algebraic cases. |\n", "| *Modifications weak* | Replaced vague suggestions with three targeted, technically valid problem alterations (RF swap, truncated cipher, known-key side channel) that directly resolve the ambiguity. |\n", "\n", "This revised strategy is structurally complete, probabilistically bounded, and cryptographically precise. It meets all constraints while explicitly acknowledging and resolving the theoretical limits of the 1-vs-2 distinction." ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "## Pattern A: Reflection and Refinement (Self-Correction Loop)\n", "\n", "# 1. Get the winning response\n", "winner_index = int(ranks[0]) - 1\n", "winner_model = competitors[winner_index]\n", "winner_answer = answers[winner_index]\n", "\n", "print(f\"Winner: {winner_model}\\n\")\n", "\n", "# 2. Ask the judge for a critique of the winning answer\n", "critique_prompt = f\"\"\"\n", "You are an expert editor. Analyze this response to the question: \"{question}\"\n", "Here is the response:\n", "---\n", "{winner_answer}\n", "---\n", "Provide a constructive critique. What are its weak points, logical gaps, or areas for improvement?\n", "Be brief and specific.\n", "\"\"\"\n", "\n", "response = openai.chat.completions.create(\n", " model=\"gpt-5.4-mini\", # or gpt-4o-mini / deepseek depending on availability\n", " messages=[{\"role\": \"user\", \"content\": critique_prompt}]\n", ")\n", "critique = response.choices[0].message.content\n", "print(\"### Critique:\\n\", critique)\n", "\n", "# 3. Feed the critique back to the winning model to get a refined version\n", "refine_prompt = f\"\"\"\n", "Here was your original answer to the question: \"{question}\"\n", "---\n", "{winner_answer}\n", "---\n", "An expert reviewer gave this critique of your answer:\n", "---\n", "{critique}\n", "---\n", "Please rewrite and improve your response, addressing all points in the critique.\n", "\"\"\"\n", "\n", "# Call the winning model (or a standard model if API limits apply)\n", "refined_response = sumopod.chat.completions.create(\n", " model=\"qwen3.6-flash\", \n", " messages=[{\"role\": \"user\", \"content\": refine_prompt}]\n", ")\n", "final_answer = refined_response.choices[0].message.content\n", "\n", "print(\"\\n### Refined Final Answer:\\n\")\n", "display(Markdown(final_answer))" ] }, { "cell_type": "code", "execution_count": 65, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "### Synthesized Master Answer:\n", "\n" ] }, { "data": { "text/markdown": [ "A good strategy is to use a small number of queries to test for the three structured cases first, and then treat the remaining two cases as indistinguishable under the stated rules.\n", "\n", "## Bottom line\n", "\n", "- **9 queries are sufficient** to identify cases 3, 4, and 5 with overwhelming confidence.\n", "- **Cases 1 and 2 cannot be distinguished information-theoretically with this budget**; under “paper reasoning” they should be grouped together unless additional assumptions are added.\n", "- If you require a unique answer among all five, then **no bounded paper-only strategy gives meaningful success on 1 vs 2** beyond a blind 50/50 guess.\n", "\n", "---\n", "\n", "# Strategy overview\n", "\n", "We proceed in this order:\n", "\n", "1. **Test for Case 5**: \\(f(x)=x\\oplus K\\)\n", "2. **Test for Case 3**: \\(f(x)=Ax\\oplus b\\)\n", "3. **Test for Case 4**: \\(f(x)=g(x_L)\\,\\|\\,h(x_R)\\)\n", "4. If none match, output **Case 1 or Case 2**\n", "\n", "The key idea is to exploit properties that are:\n", "\n", "- exact for the target case,\n", "- extremely unlikely for a random permutation or AES under a tiny query budget.\n", "\n", "---\n", "\n", "# Query plan\n", "\n", "Let \\(0^{128}\\) denote the all-zero string.\n", "\n", "Use these nine inputs in order, adaptively if desired, though the first six can be fixed in advance:\n", "\n", "1. \\(x_0 = 0^{128}\\)\n", "2. \\(x_1 = 0^{127}1\\) (value 1)\n", "3. \\(x_2 = 0^{126}10\\) (value 2)\n", "4. \\(x_3 = 0^{125}100\\) (value 4)\n", "5. \\(x_4 = x_1 \\oplus x_3\\) (value 5)\n", "6. \\(x_5 = x_2 \\oplus x_3\\) (value 6)\n", "7. \\(x_6 = 1\\ll 127\\) (a bit in the left 64-bit half)\n", "8. \\(x_7 = 1\\ll 63\\) (a bit in the right 64-bit half)\n", "9. \\(x_8 = x_6 \\oplus x_7\\)\n", "\n", "Let the corresponding outputs be \\(y_i=f(x_i)\\).\n", "\n", "---\n", "\n", "# Decision procedure\n", "\n", "## Step 1: Test Case 5, the XOR cipher \\(f(x)=x\\oplus K\\)\n", "\n", "For this case,\n", "\\[\n", "f(x)\\oplus x = K\n", "\\]\n", "for every input \\(x\\). So the output differs from the input by one fixed constant.\n", "\n", "Compute:\n", "\\[\n", "K_0 = y_0 \\oplus x_0 = y_0,\\quad\n", "K_1 = y_1 \\oplus x_1,\\quad\n", "K_2 = y_2 \\oplus x_2.\n", "\\]\n", "\n", "### Rule\n", "- If \\(K_0=K_1=K_2\\), declare **Case 5**.\n", "- Otherwise continue.\n", "\n", "### Why this works\n", "In Case 5 it holds with probability 1.\n", "For cases 1, 2, 3, and 4, the chance that three unrelated 128-bit equalities all happen is negligible, about \\(2^{-256}\\) or smaller in practice.\n", "\n", "---\n", "\n", "## Step 2: Test Case 3, the affine map \\(f(x)=Ax\\oplus b\\)\n", "\n", "Affine maps satisfy:\n", "\\[\n", "f(u\\oplus v)=f(u)\\oplus f(v)\\oplus f(0).\n", "\\]\n", "Equivalently, for any fixed \\(\\Delta\\),\n", "\\[\n", "f(x\\oplus\\Delta)\\oplus f(x)\n", "\\]\n", "is constant in \\(x\\), and equals \\(A\\Delta\\).\n", "\n", "Use \\(\\Delta=x_3\\) (the value 4). Then:\n", "- \\(x_4=x_1\\oplus \\Delta\\)\n", "- \\(x_5=x_2\\oplus \\Delta\\)\n", "\n", "Compute:\n", "\\[\n", "D_1 = y_4\\oplus y_1,\\quad\n", "D_2 = y_5\\oplus y_2.\n", "\\]\n", "\n", "### Rule\n", "- If \\(D_1=D_2\\), declare **Case 3**.\n", "- Otherwise continue.\n", "\n", "You may also optionally check consistency with \\(x_0\\):\n", "\\[\n", "y_3\\oplus y_0 = D_1\n", "\\]\n", "for an even stronger test, but two pairs are enough for a clean distinguisher.\n", "\n", "### Why this works\n", "For an affine function, the difference across a fixed input mask is exactly constant. \n", "For a random permutation, AES, or Case 4, this kind of exact equality among unrelated output differences is overwhelmingly unlikely.\n", "\n", "Note that Case 5 also satisfies affine behavior, which is why we test Case 5 first.\n", "\n", "---\n", "\n", "## Step 3: Test Case 4, the split permutation\n", "\\[\n", "f(x_L,x_R)=g(x_L)\\,\\|\\,h(x_R),\n", "\\]\n", "where \\(g\\) and \\(h\\) are independent random permutations on 64-bit strings.\n", "\n", "This case has a very special “half-independence” property:\n", "\n", "- changing the **right half** of the input does **not** change the **left half** of the output;\n", "- changing the **left half** of the input does **not** change the **right half** of the output.\n", "\n", "Use:\n", "- \\(x_6 = 1\\ll 127\\) : changes only the left half,\n", "- \\(x_7 = 1\\ll 63\\) : changes only the right half,\n", "- \\(x_8 = x_6\\oplus x_7\\): changes both halves.\n", "\n", "Let \\(y_6,y_7,y_8\\) be the outputs.\n", "\n", "### Rule\n", "Check the following four conditions:\n", "1. \\(y_6[R]=y_0[R]\\)\n", "2. \\(y_7[L]=y_0[L]\\)\n", "3. \\(y_8[L]=y_6[L]\\)\n", "4. \\(y_8[R]=y_7[R]\\)\n", "\n", "If all hold, declare **Case 4**.\n", "\n", "### Why this works\n", "In Case 4:\n", "- \\(x_6\\) and \\(x_0\\) have the same right half, so their right-output halves must match;\n", "- \\(x_7\\) and \\(x_0\\) have the same left half, so their left-output halves must match;\n", "- \\(x_8\\) combines the left behavior of \\(x_6\\) and the right behavior of \\(x_7\\).\n", "\n", "For cases 1, 2, or 3, the output halves are not constrained this way, so these equalities happen only with probability about \\(2^{-64}\\) each, making false positives negligible.\n", "\n", "---\n", "\n", "# Final classification\n", "\n", "If none of the above tests succeeds:\n", "\n", "- output **Case 1 or Case 2**\n", "\n", "That is the best possible conclusion under the stated rules.\n", "\n", "---\n", "\n", "# Why cases 1 and 2 are indistinguishable here\n", "\n", "## Case 1: uniformly random permutation on 128-bit strings\n", "## Case 2: AES-128 with unknown key\n", "\n", "From a black-box perspective and with only 2,000 queries, **both behave like permutations with no reusable algebraic structure visible by paper reasoning**.\n", "\n", "- A truly random permutation has no exploitable pattern.\n", "- AES is specifically designed to be a pseudorandom permutation, so a manual adversary with tiny query budget should not expect a visible distinguisher.\n", "- The birthday bound is irrelevant here: with only 2,000 queries in a 128-bit domain, accidental collisions are essentially impossible in either case.\n", "\n", "So within this setup, **1 vs 2 is not realistically distinguishable**.\n", "\n", "---\n", "\n", "# Minimum number of queries\n", "\n", "A reasonable lower bound for this style of reasoning is:\n", "\n", "- **3 queries** to test Case 5 strongly,\n", "- **5–6 queries** to test affine structure robustly,\n", "- **9 queries** to also test the split-permutation structure cleanly.\n", "\n", "So:\n", "\n", "- **Best practical answer: 9 queries**\n", "- **Absolute minimum for partial identification:** 3 or 4 queries, but not enough to cleanly separate all structured cases.\n", "\n", "---\n", "\n", "# Transcript-based decision summary\n", "\n", "Given outputs \\(y_0,\\dots,y_8\\):\n", "\n", "1. If \\(y_i\\oplus x_i\\) is constant for \\(i=0,1,2\\), output **5**\n", "2. Else if \\(y_4\\oplus y_1 = y_5\\oplus y_2\\), output **3**\n", "3. Else if the four half-equality checks for \\(y_6,y_7,y_8\\) all hold, output **4**\n", "4. Else output **1 or 2**\n", "\n", "---\n", "\n", "# If you want all five cases distinguishable\n", "\n", "You must change the problem. The cleanest modification is:\n", "\n", "- Replace Case 1 with a **random function** instead of a random permutation.\n", "\n", "Then Case 1 would be distinguishable from Case 2 and from the structured cases by collisions, while the other tests still work.\n", "\n", "Alternatively, if you want to separate AES from a random permutation, you need either:\n", "- far more than 2,000 queries plus a concrete known distinguisher, or\n", "- computational power, which the problem explicitly forbids.\n", "\n", "---\n", "\n", "# Final answer\n", "\n", "Use a **9-query adaptive strategy** that tests, in order:\n", "\n", "1. constant XOR offset,\n", "2. affine additivity,\n", "3. left/right-half independence.\n", "\n", "This identifies cases **5, 3, and 4** with overwhelming confidence. \n", "If none match, return **“case 1 or case 2”**, because under the stated constraints those two are not meaningfully distinguishable." ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "## Pattern B: Synthesis (Best-of-All Ensembling)\n", "\n", "# Extract the top 2 answers\n", "top_1_answer = answers[int(ranks[0]) - 1]\n", "top_2_answer = answers[int(ranks[1]) - 1]\n", "\n", "synthesis_prompt = f\"\"\"\n", "You are a master synthesist. Below are two highly-rated answers to the question: \"{question}\"\n", "\n", "Answer 1:\n", "---\n", "{top_1_answer}\n", "---\n", "\n", "Answer 2:\n", "---\n", "{top_2_answer}\n", "---\n", "\n", "Analyze both answers. Combine the strongest arguments, best phrasing, and unique insights from both \n", "into a single, cohesive, and superior final response. Output only the final synthesized response.\n", "\"\"\"\n", "\n", "response = openai.chat.completions.create(\n", " model=\"gpt-5.4-mini\",\n", " messages=[{\"role\": \"user\", \"content\": synthesis_prompt}]\n", ")\n", "synthesized_answer = response.choices[0].message.content\n", "\n", "print(\"### Synthesized Master Answer:\\n\")\n", "display(Markdown(synthesized_answer))\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", " \n", " \n", " \n", " \n", "
\n", " \n", " \n", "

Commercial implications

\n", " These kinds of patterns - to send a task to multiple models, and evaluate results,\n", " are common where you need to improve the quality of your LLM response. This approach can be universally applied\n", " to business projects where accuracy is critical.\n", " \n", "
" ] } ], "metadata": { "kernelspec": { "display_name": ".venv", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.12" } }, "nbformat": 4, "nbformat_minor": 2 }