[Crypto] baby_N1ES - CirQ xp0int Posted on Mar 12 2018 ? Crypto ? ? feistel ? 看题目名字就能猜测和DES有关系,直接看所给的python代码也能看出和现有的DES遵循一个同样的框架,更确切来说,和现行DES都遵循feistel结构,其中要求轮函数F是自反的,即 $$F(x)=y\ \ \Leftrightarrow\ \ F(y)=x$$ 这里的$F$就是代码中的`round_add`函数,很容易能写出对应的解密函数,跟加密函数完全相反就可以。 ```python def encrypt(self, plaintext): if (len(plaintext) % 16 != 0 or isinstance(plaintext, bytes) == False): raise Exception("plaintext must be a multiple of 16 in length") res = '' for i in range(len(plaintext) / 16): block = plaintext[i * 16:(i + 1) * 16] L = block[:8] R = block[8:] for round_cnt in range(32): L, R = R, (round_add(L, self.Kn[round_cnt])) L, R = R, L res += L + R return res def decrypt(self, ciphertext): if (len(ciphertext) % 16 != 0 or isinstance(ciphertext, bytes) == False): raise Exception("ciphertext must be a multiple of 16 in length") res = '' for i in range(len(ciphertext) / 16): block = ciphertext[i * 16:(i + 1) * 16] L = block[:8] R = block[8:] L, R = R, L for round_cnt in range(32): L, R = (round_add(R, self.Kn[-1-round_cnt])), L res += L + R return res ``` 代码写在`N1ES`类中,由于使用的是相同的密钥,直接改challenge.py中的代码即可: ```python from N1ES import N1ES import base64 key = "wxy191iss00000000000cute" n1es = N1ES(key) #flag = "N1CTF{*****************************************}" #cipher = n1es.encrypt(flag) #print base64.b64encode(cipher) cipher = base64.b64decode('HRlgC2ReHW1/WRk2DikfNBo1dl1XZBJrRR9qECMNOjNHDktBJSxcI1hZIz07YjVx') print n1es.decrypt(cipher) ``` **Flag** N1CTF{F3istel_n3tw0rk_c4n_b3_ea5i1y_s0lv3d_/--/} 打赏还是打残,这是个问题 赏 Wechat Pay Alipay [Crypto] rsa_padding - CirQ [PWN]Beeper - Cpt.shao
没有帐号? 立即注册