Bugku11月11日是个好日子wp 1.打开附件发现重点alp slbn7q6u0w2pf3m9tzjx8o51yke????dhc4icipher:6MBphWqgEun4VXNkcKbdaVDNrpw3714BigGaiwKKC7z7KJ6MxkHYf4G4dFsKWU78VgmHgsEJdKwPCb3j495tg4FUAd5hkRxzmGEiggRWye9k8ddd3P5CXdEgRgqgjxgw48pPPBdM7oB14z4WPEmFqFcPvKXwbE5bzFVDCESnyaB3Z47hint:不 会 吧 就 这 ¿ 不 会 吧 就 这 ¿ 不 会 吧 就 这 ¿ 就 这 ¿ 就 这 ¿ 不 会 吧 就 这 ¿ 不 会 吧 就 这 ¿ 就 这 ¿ 不 会 吧 就 这 ¿ 就 这 ¿ 就 这 ¿ 不 会 吧 就 这 ¿ 不 会 吧 就 这 ¿ 不 会 吧 不 会 吧 就 这 ¿ 就 这 ¿ 不 会 吧 就 这 ¿ 不 会 吧 就 这 ¿ 不 会 吧 就 这 ¿ 不 会 吧 不 会 吧 不 会 吧 不 会 吧 就 这 ¿ 不 会 吧 就 这 ¿ 不 会 吧 不 会 吧 就 这 ¿ 不 会 吧 就 这 ¿ 就 这 ¿ 就 这 ¿ 就 这 ¿ 就 这 ¿ 就 这 ¿ 就 这 ¿ 不 会 吧 不 会 吧 不 会 吧 不 会 吧 不 会 吧 不 会 吧 不 会 吧 不 会 吧 不 会 吧 不 会 吧 不 会 吧 就 这 ¿ 就 这 ¿ 就 这 ¿ 就 这 ¿ 不 会 吧 不 会 吧 就 这 ¿ 就 这 ¿ 就 这 ¿ 就 这 ¿ 不 会 吧 不 会 吧 就 这 ¿ 就 这 ¿ 就 这 ¿ 就 这 ¿ 不 会 吧 就 这 ¿ 就 这 ¿ 不 会 吧 不 会 吧 就 这 ¿ 不 会 吧 不 会 吧 就 这 ¿ 就 这 ¿ 就 这 ¿ 就 这 ¿ 不 会 吧 不 会 吧 不 会 吧 就 这 ¿ 就 这 ¿ 就 这 ¿ 就 这 ¿ 不 会 吧 就 这 ¿ 不 会 吧 就 这 ¿ 不 会 吧 就 这 ¿ 就 这 ¿ 不 会 吧 不 会 吧 不 会 吧 不 会 吧 不 会 吧 就 这 ¿ 不 会 吧 就 这 ¿ 不 会 吧 就 这 ¿ 不 会 吧 就 这 ¿ 不 会 吧 就 这 ¿ 不 会 吧 就 这 ¿ 不 会 吧 不 会 吧 不 会 吧 就 这 ¿ 就 这 ¿ 不 会 吧 就 这 ¿ 不 会 吧 就 这 ¿ 就 这 ¿ 就 这 ¿ 不 会 吧 就 这 ¿ 不 会 吧 不 会 吧 就 这 ¿ 就 这 ¿ 不 会 吧 不 会 吧 不 会 吧 就 这 ¿ 就 这 ¿ 就 这 ¿ 就 这 ¿ 就 这 ¿ 就 这 ¿ 就 这 ¿ 就 这 ¿ 不 会 吧 就 这 ¿ 不 会 吧 就 这 ¿ 不 会 吧 就 这 ¿ 不 会 吧 就 这 ¿ 就 这 ¿ 就 这 ¿ 就 这 ¿ 就 这 ¿ 就 这 ¿ 不 会 吧 不 会 吧 不 会 吧 就 这 ¿ 不 会 吧 就 这 ¿ 不 会 吧 就 这 ¿ 就 这 ¿ 不 会 吧 不 会 吧 不 会 吧 就 这 ¿ 就 这 ¿ 就 这 ¿ 就 这 ¿ 就 这 ¿ 就 这 ¿ 就 这 ¿ 就 这 ¿ 就 这 ¿ 不 会 吧 就 这 ¿ 不 会 吧 不 会 吧 就 这 ¿ 不 会 吧 就 这 ¿ 不 会 吧 不 会 吧 就 这 ¿ 不 会 吧 不 会 吧 就 这 ¿ 就 这 ¿ 不 会 吧 就 这 ¿ 不 会 吧 不 会 吧 就 这 ¿ 不 会 吧 不 会 吧 不 会 吧 就 这 ¿ 不 会 吧 就 这 ¿ 不 会 吧 就 这 ¿ 就 这 ¿ 不 会 吧 就 这 ¿ 不 会 吧 就 这 ¿ 就 这 ¿ 就 这 ¿ 不 会 吧 不 会 吧 不 会 吧 不 会 吧 不 会 吧 不 会 吧 不 会 吧 不 会 吧 不 会 吧 就 这 ¿ 就 这 ¿ 就 这 ¿ 就 这 ¿ 不 会 吧 不 会 吧 就 这 ¿ 就 这 ¿ 不 会 吧 就 这 ¿ 不 会 吧 不 会 吧 就 这 ¿ 不 会 吧 不 会 吧 就 这 ¿ 就 这 ¿ 不 会 吧 不 会 吧 不 会 吧 就 这 ¿ 不 会 吧 就 这 ¿ 就 这 ¿ 就 这 ¿ 不 会 吧 就 这 ¿ 不 会 吧 不 会 吧 就 这 ¿ 就 这 ¿ 就 这 ¿ 就 这 ¿ 不 会 吧 就 这 ¿ 就 这 ¿ 就 这 ¿ 就 这 ¿ 不 会 吧 不 会 吧 不 会 吧 不 会 吧 不 会 吧 就 这 ¿ 不 会 吧 不 会 吧 就 这 ¿ 就 这 ¿ 不 会 吧 就 这 ¿ 不 会 吧 就 这 ¿ 不 会 吧 不 会 吧 不 会 吧 就 这 ¿ 就 这 ¿ 就 这 ¿ 就 这 ¿ 不 会 吧 就 这 ¿ 不 会 吧 就 这 ¿ 不 会 吧 不 会 吧 就 这 ¿ 不 会 吧 不 会 吧 就 这 ¿ 不 会 吧 就 这 ¿ 不 会 吧 就 这 ¿ 不 会 吧 不 会 吧 不 会 吧 不 会 吧 就 这 ¿ 不 会 吧 就 这 ¿ 不 会 吧 就 这 ¿ 不 会 吧 就 这 ¿ 就 这 ¿ 不 会 吧 不 会 吧 不 会 吧 就 这 ¿ 就 这 ¿ 不 会 吧 不 会 吧 就 这 ¿2.先看看hint给我们什么提示发现是阴阳怪气编码得到先套娃alp只在最后一步用注意数字哦的提示3.那就说明前面是嵌套加密发现是base64混合加密得到en,i5d8{unw_ad1_f2_pg_8gea}4.en,不看的话后面满足flag格式是替换密码需要我们思考alp slbn7q6u0w2pf3m9tzjx8o51yke????dhc4i的作用5.发现alp中数字字母只出现一次猜测是没出现的字符得到agrv6.写仿射密码脚本解密from itertools import permutations # # 扩展欧几里得算法 / 模逆元 # def egcd(a, b): if b 0: return a, 1, 0 g, x1, y1 egcd(b, a % b) return g, y1, x1 - (a // b) * y1 def modinv(a, m): a a % m g, x, _ egcd(a, m) if g ! 1: return None return x % m # # 仿射加解密 # def affine_encrypt(plaintext, a, b, origin): m len(origin) out [] for ch in plaintext: idx origin.find(ch) out.append(origin[(a * idx b) % m] if idx ! -1 else ch) return .join(out) def affine_decrypt(ciphertext, a, b, origin): m len(origin) a_inv modinv(a, m) if a_inv is None: return None out [] for ch in ciphertext: idx origin.find(ch) out.append(origin[(a_inv * (idx - b)) % m] if idx ! -1 else ch) return .join(out) # # 解题主流程 # def solve(): # ---- 题目数据 ---- ciphertext en,i5d8{unw_ad1_f2_pg_8gea} origin_template slbn7q6u0w2pf3m9tzjx8o51yke????dhc4i unknown_chars agrv crib flag{ # 明文约束 # ---- 生成所有可能的完整字母表去重 ---- unknown_count origin_template.count(?) perms set(permutations(unknown_chars, unknown_count)) alphabets [] for chars in perms: origin origin_template for ch in chars: origin origin.replace(?, ch, 1) if len(set(origin)) len(origin): # 字母表无重复字符 alphabets.append(origin) m len(alphabets[0]) # 完整字母表长度 36 a_values [a for a in range(1, m) if modinv(a, m) is not None] b_values range(m) print(f[*] 完整字母表长度: {m}) print(f[*] 与 {m} 互质的 a 值: {a_values}) print(f[*] 有效字母表排列: {len(alphabets)} 种) print(f[*] 总尝试次数: {len(a_values)} × {m} × {len(alphabets)} f {len(a_values) * m * len(alphabets)}\n) results [] count 0 for origin in alphabets: for a in a_values: a_inv modinv(a, m) for b in b_values: count 1 plaintext affine_decrypt(ciphertext, a, b, origin) if plaintext and crib.lower() in plaintext.lower(): # 加密回验确保自洽 if affine_encrypt(plaintext, a, b, origin) ciphertext: results.append((a, b, origin, plaintext)) # ---- 输出去重后的结果 ---- print(f[*] 共尝试 {count} 次命中 {len(results)} 条按 (a,b,字母表,明文) 去重\n) seen set() for a, b, origin, plaintext in results: key (a, b, origin, plaintext) if key in seen: continue seen.add(key) print(fa{a}, b{b}) print(f字母表: {origin}) print(f明文 : {plaintext}) print(- * 60) # 提取标准 flag for _, _, _, plaintext in seen: if flag{ in plaintext: import re match re.search(rflag\{[^}]*\}, plaintext) if match: print(f\n[✔] 最终 Flag: {match.group(0)}) return match.group(0) print(\n[-] 未找到含 flag{...} 的明文) return None if __name__ __main__: solve()7.可以做筛查也可以自己筛查oh,flag{the_day_13_s0_g0od}是最终明文结果8.总结学习阴阳怪气解码的同时锻炼仿射密码解题并且推导的部分也很有趣。