#!/bin/bash # 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-2026-crypto-ENChannel # Writeup (from instruction.md) - commented out below. # ============================================================ # # # > 以下为解题 writeup 全文,供参考。 # # 由 qwen 随机生成 dialogue,每句话按照 32 字节分块后随机填充,每块被分别加密到 BFV 密文中,可以选择 14 次 Galois key,并且给出一次解密机会,返回解密结果中 256 个系数,要求还原出 dialogue 的摘要。 # # 该题是对 r3ctf2024 tinyseal 在多信息的拓展,对于 tinyseal 只需要将一个对 $\sum m_ix^i$ 的加密 $\text{Enc}(\sum m_ix^i)$ 通过运算去掉除常数系数的所有项,在这里需要处理多个密文,并且将常数系数拼凑到合适的位置。 # # 对于从 $\text{ENC}(\sum m_ix^i)$ 得到 $\text{ENC}(m_0)$ 的过程,最简单的是通过执行 trace 函数,这个过程需要 $\log N$ 次 ks 操作。通过迭代地执行 $c+\tau_{2^l+1}(c)$ # # 简单地重复进行 trace 对于 $l$ 个密文总共需要 $l\log N$ 次 ks 操作,在这里存在算法优化,可以将 ks 次数减少到 $l$ 次。主要的 insight 是观察到在执行 trace 的过程中存在一些空槽位可以插入。可以通过做一个类似树结构的排列,省去一个 $\log N$ 的因子,具体细节可以参考 https://eprint.iacr.org/2020/015。 # # 实际上由于此处算法优化也只是减少十几倍,通过并行的方式也是可以做到的。 # # ## Hints # # * 利用同态加密的Galois操作与Trace机制,可通过迭代加法逐步消除多项式高次项,提取常数系数。 # * 多密文场景下需设计树状排列或并行策略,将分散的常数系数对齐至统一位置,从而大幅减少密钥切换次数。 # * 受限于Galois密钥调用次数与单次解密返回的系数范围,需合理编排密文运算顺序以高效利用有限查询。 # * 提取的常数系数对应原始数据分块的特定偏移量,结合已知分块长度与填充规律可逆向重构目标摘要。 # * 理论上的算法优化可降低计算阶数,实际解题时亦可借助并行计算或分块处理满足时间要求。 # # ============================================================ # 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 'YWxpY3Rme3IxbmdfcEBja2luZ18xc19mdW5fZW5vdWdofQ==' | base64 -d > /logs/agent/flag.txt