0%

Crypto-特殊的日子

特殊的日子

每个人的一生中都会或多或少有那么几个对自己很重要的日子,比如对于我来说,这一天就很重要。
答案格式wctf{日期} //友情提示,此题需要暴力破解,但只是爆破这段密文,不是爆破这个网站。。 = =!

题目里提到了暴力破解,应该就是某种不可逆的编码了。我学的比较少,刚开始想到的当然是MD5,不过MD5显然没有8位的。。。

后来直接查了查,发现是CRC32,这个好像在压缩包那边看到过。然后写程序,CRC32在 zlib 里面。

Note

To generate the same numeric value across all Python versions and platforms, use crc32(data) & 0xffffffff. If you are only using the checksum in packed binary format this is not necessary as the return value is the correct 32-bit binary representation regardless of sign.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import zlib

def crc32(para):
res = zlib.crc32(para.encode("utf-8"))
return '%x' % (res & 0xffffffff)

std = '4D1FAE0B'.lower()
for year in range(1500,3000):
for month in range(1,13):
for day in range(1,32):
syyyy = str(year)
smm = str(month)
if month < 10:
smm = '0' + smm
sdd = str(day)
if day < 10:
sdd = '0' + sdd
now = syyyy + smm + sdd
if crc32(now) == std:
print(now)

还看到有一种高端的写法:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import zlib
def crc32(st):
crc = zlib.crc32(st.encode('utf-8'))
if crc > 0:
return "%x" % (crc & 0xffffffff)
else:
return "%x" % (crc & 0xffffffff)

#生成年'1000'~'3000'
year = [str(i) for i in range(1000,3000)]
#生成月'01'~'12'
month = [str(i) if i>9 else (str(0)+str(i)) for i in range(1,13) ]
#生成日'01'~'31'
day = [str(i) if i>9 else (str(0)+str(i)) for i in range(1,32) ]

#题目所给
realDate = '4D1FAE0B'.lower()

#穷举日期计算crc32值然后与题目给的值进行比对,一样则输出
import itertools
#利用itertools.product()生成年月日的所有组合
for item in itertools.product(year,month,day):
date = ''.join(item)
if crc32(date) == realDate:
print(date)
咖啡,亦我所需也