# 方法

$y = x \oplus (x \ggg p) \oplus (x \ggg q)$

$y \ggg p = (x \ggg p) \oplus (x \ggg 2p) \oplus (x \ggg (p + q))\\ y \ggg q = (x \ggg q) \oplus (x \ggg 2q) \oplus (x \ggg (p + q))$

$y \oplus (y \ggg p) \oplus (y \ggg q) = x \oplus (x \ggg 2p) \oplus (x \ggg 2q)$

$y^{(n)} = x \oplus (x \ggg p \times 2^n) \oplus (x \ggg q \times 2^n)$

$x = x \ggg p \times 2^n\\x = x \ggg q \times 2^n$

$y^{(n)} = x$

def move(n, k):
s = bin(n)[2:].zfill(64)
k &= 63
return int(s[k:] + s[:k], 2)

def encrypt(x, ks):
return xor(x, reduce(xor, map(lambda k: move(x, k), ks)))

def decrypt(y, ks):
for _ in range(6):
y = encrypt(y, ks)
ks = [k << 1 for k in ks]
return y


# 另一种方法

\begin{aligned} L(a) & = x^{k_1}a(x) + x^{k_2}a(x) + ... +x^{k_n}a(x) & \bmod(x^m + 1)\\ & = (x^{k_1} + x^{k_2} + ... + x^{k_n})a(x) & \bmod(x^m + 1)\\ & = k(x)a(x) & \bmod(x^m + 1) \end{aligned}

$奇数项 \iff k(1) = 1 \iff 不含 x + 1 因子 \iff 有逆元\\ 偶数项 \iff k(1) = 0 \iff 含有 x + 1 因子 \iff 无逆元$

posted @ 2022-02-23 13:55  Tf1shC4T  阅读(433)  评论(0编辑  收藏  举报