Brute-Force-Attack on Triple-DES with Reduced Key Space

题目地址:https://www.mysterytwisterc3.org/en/challenges/level-ii/brute-force-attack-on-triple-des-with-reduced-key-space

题意:DES3暴力题,需要根据题目找出密钥的信息,https://en.wikipedia.org/wiki/Custom_hardware_attack,这是key中前10个字母的来源,然后利用库函数暴力即可。

注意解是明文的第一行,而不是key。

而且虽然题目中说要编码成16进制,但我们用库函数解决,库函数的输入是明文,而不是hex编码

 1 #coding:utf-8
 2 from Crypto.Cipher import DES3
 3 import re
 4 with open('ex1.txt','r') as fp:
 5     data="".join(fp.read().split())   #split消除一切空格和回车
 6 max1=0
 7 for k in range(0,999999+1):
 8     tmp = str(k).zfill(6)
 9     key = 'COPACOBANA'+ tmp
10     cipher = DES3.new(key,DES3.MODE_CBC, "00000000")#初始向量,需为8的倍数,做过PA2应该理解他的含义  DES3.MODE_CBC
11     mtext = cipher.decrypt(data.decode('hex'))
12     num = len(re.findall('[a-zA-Z ]',mtext))
13     if  num>max1:
14         max1 = num
15         Mtext = mtext
16         Key = key
17 print "key:", Key
18 print Mtext

 

posted @ 2017-10-09 23:23  Elpsywk  阅读(432)  评论(0编辑  收藏  举报