被拉来打的,只做了 Crypto。做啥写啥。
100 Points
要么照着题目随便搞搞,要么搜索一下,大部分就是古典密码或者轮换替换,批量一键过题。
- basic-mod*:照着题目说法写一个
f然后''.join(map(lambda x: chr(f(int(x))), input.strip().split()))。 - credstuff:
grep -in cultiris usernames.txt | awk -F ':' '{print $1}' | xargs head passwords.txt -n,然后 ROT13。 - morse-code:https://morsecode.world/international/decoder/audio-decoder-adaptive.html。
- rail-fence:https://gchq.github.io/CyberChef/#recipe=Rail_Fence_Cipher_Decode(4,0)。
- substitution*:https://www.quipqiup.com/。
- transposition-trial:
''.join((input[i+2] + input[i:i+2]) for i in range(0, len(input), 3))。 - Vigenere:https://gchq.github.io/CyberChef/#recipe=Vigen%C3%A8re_Decode('')。
Very Smooth
审计 get_smooth_prime,发现 $p-1$ 是光滑质数,所以用 Pollard’s p-1 算法分解质因子:
| |
然后直接跑就行了。
| |
Sequences
直接审计 m_func:
| |
$$ f(x) = \begin{cases}x+1, &1\le x\le 3\\21f(x-1)+301f(x-2)-9549f(x-3)+55692f(x-4),&3<x\end{cases}, x\in\N^+ $$
一个非常经典的线性递推。因为 iter 数量有 $2\times10^7$ 次,直接递推也是不太方便的,考虑矩阵快速幂优化线性递推。
$$ \begin{bmatrix}f(x+3)\\f(x+2)\\f(x+1)\\f(x)\end{bmatrix}=\begin{bmatrix}21&301&-9549&55692\\1&0&0&0\\0&1&0&0\\0&0&1&0\end{bmatrix}^x\cdot\begin{bmatrix}f(3)\\f(2)\\f(1)\\f(0)\end{bmatrix} $$
对这个方法不太了解的可以参考 https://oi-wiki.org/math/fibonacci/#_5。
注意 numpy 默认的数据类型会爆精度,需要手动指定 dtype='object'。同时该取模的地方要取上。
| |
Sum-O-Primes
不知道为什么这个题要给 400 points。
| |
NSA Backdoor
首先 $p-1$ 和 $q-1$ 都是光滑的,直接用 Pollard’s p-1 算法搞出来。
搞出来后注意到我们要求解的式子,是一个离散对数问题: $$ c= 3^{\text{FLAG}} \pmod n $$ 朴素的 BSGS 复杂度太高,直接算算不了。由于 $n=p\times q$,而 $p$,$q$ 都是光滑质数,而且根据生成方式,$p$ 和 $q$ 的质因子不大,数量也不多,提示我们可以用 Pohlig-Hellman 算法求离散对数。
具体的算法可以参考 https://ctf-wiki.org/crypto/asymmetric/discrete-log/discrete-log/#pohlig-hellman-algorithm。我直接用 sage 算了。
| |