先给结论,Python 的实现:
1 | def i_pow(n): |
题目:XYCTF 2025 - Misc - sins
题目内容:(没必要看)
1 | “Come now, let us settle the matter,” says the LORD. “Though your sins are like scarlet, they shall be as white as snow; though they are red as crimson, they shall be like wool. - Isaiah 1:18 |
题目附件 sins.py
:
1 | from secret import flag |
题解 WriteUp
分析代码可知,我们需要编写一个 Python Lambda 表达式,题目对这个表达式的要求是:
- 只能包含
i0123456789+-*%/^=<>~&|:()[]
这些字符,不可以出现 逗号,
、空格i
的其它字母 等等。 - 长度小于 16.
- 不能访问任何全局变量或函数,只能使用表达式中的运算和
i
变量。 - 以字符串类型返回虚数单位 $$i$$ 的传入参数
i
次幂。也就是说结果是在1
i
-1
-i
循环。
开始看题后,搓了两个小时,终于得到了最终的表达式,且长度为 15,成功满足了题目所有要求:
1 | '1i--'[i%4::-2] |
flag: XYCTF{Thy_sins_are_forgiven_thee}
最终一共有 8 队伍解出。这题可谓是把 Python 的字符串截取玩到一定境界了,思路也很重要。