一道与普通rsa不太相同的题,基本没见过这个思路,但实际上并不难,需要一点数学的直觉。
直接看代码可以知道,所使用的消息、大整数和加密指数都是固定的,但需要用户自行输入一个padding,加密过程是:
其中的值固定为3,但因为消息过长,三次方后超过,导致直接开立方不奏效。由于密钥参数都是确定的,因此可以用两次加密作差来解决求模的问题,记为,密文为,那么两次加密的结果记做:
直接相减可以消去的立方项,由于
看题目名字就能猜测和DES有关系,直接看所给的python代码也能看出和现有的DES遵循一个同样的框架,更确切来说,和现行DES都遵循feistel结构,其中要求轮函数F是自反的,即
这里的就是代码中的round_add函数,很容易能写出对应的解密函数,跟加密函数完全相反就可以。
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, Lres += L + Rreturn resdef decrypt(self, ciphertext):if (len(ciphertext) % 16 != 0 or isinstance(ciphertext, bytes) == False):raise Exception("ciphertext must be a multiple of 16 in