| # Copyright (c) 2026 Alibaba Group and its affiliates | |
| # Licensed under the Apache License, Version 2.0 (the "License"); | |
| # you may not use this file except in compliance with the License. | |
| # You may obtain a copy of the License at | |
| # http://www.apache.org/licenses/LICENSE-2.0 | |
| # Unless required by applicable law or agreed to in writing, software | |
| # distributed under the License is distributed on an "AS IS" BASIS, | |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| # See the License for the specific language governing permissions and | |
| # limitations under the License. | |
| # ============================================================ | |
| # Challenge: aliyunctf-2025-Crypto-PRFCasino | |
| # Writeup (from instruction.md) - commented out below. | |
| # ============================================================ | |
| # | |
| # | |
| # > 以下为解题 writeup 全文,供参考。 | |
| # | |
| # ## PRFCasino | |
| # | |
| # + Category: **Crypto** | |
| # + Difficulty: ★☆ | |
| # + Tag: **ARX, Feistel** | |
| # | |
| # ## Description | |
| # | |
| # Are you Super Guesser 🍀 | |
| # | |
| # ## Solution | |
| # | |
| # 利用 ARX 和 Feistel 结构构造的 PRF,题目需要区分 PRF 输出与随机输出。 | |
| # | |
| # 需要观察到 `T+T<<<20` 结构的特殊性 | |
| # | |
| # $T\lll20=2^{20}T\ mod\ 2^{64}-1$ | |
| # | |
| # $\Rightarrow R+T\lll20+T\ mod\ 2^{64}=R+T\lll20+T-k\cdot2^{64}=R+(2^{20}+1)T-k\cdot 2^{64}\ mod\ 2^{64}-1$ | |
| # | |
| # $\because 2^{20}+1=2^{64}-1=0\ mod\ 17$ | |
| # | |
| # $\Rightarrow L'=R+T\lll20+T=R-k\cdot 2^{64}\ mod\ 17$,其中 $k\in\{0,1,2\}$ | |
| # | |
| # $\Rightarrow L'-R=-k\cdot 2^{64}=-k\ mod\ 17$ | |
| # | |
| # 下面考虑这个性质的扩散程度,注意到对于一轮 $L'-R$ 为 0,15,16 的概率分别为 $\frac{1}{6},\frac{1}{6},\frac{2}{3}$ | |
| # | |
| # 考虑经过 15 次叠加后的 $L_{end}-R$ 在模 17 上的分布状态,可以视为多项式卷积 | |
| # | |
| # ```python | |
| # PR.<x> = PolynomialRing(QQ) | |
| # f = 1/6+1/6*x^15+2/3*x^16 | |
| # coeff = list(f**15%(x^17-1)) | |
| # for _ in range(len(coeff)): | |
| # coeff[_] = round(coeff[_],6) | |
| # ``` | |
| # | |
| # 由于 2 与 11 在分布上存在较大差异,利用这一点进行区分 | |
| # | |
| # ## Hints | |
| # | |
| # - 本题核心目标为区分伪随机函数(PRF)输出与真随机数据。 | |
| # - 重点分析 ARX 与 Feistel 结构中特定加法与循环移位组合的代数特性。 | |
| # - 发现该操作会使左右分支差值在模 17 下呈现固定的偏移规律与非均匀分布。 | |
| # - 利用多项式卷积或概率转移模型推演该偏移量在多轮迭代后的累积扩散效果。 | |
| # - 通过统计检验对比实际输出与理想随机分布在特定指标上的显著差异以构造区分器。 | |
| # | |
| # ============================================================ | |
| # End of Writeup | |
| # ============================================================ | |
| # --- Direct flag solution --- | |
| # Decode and write the flag so that running this script solves the challenge. | |
| mkdir -p /logs/agent | |
| echo -n 'YWxpeXVuY3Rme1RoMTVfUFJGX24wdF9yNG5kb21fM25vdWdofQ==' | base64 -d > /logs/agent/flag.txt | |