BruteForce


Crypto - BruteForce Writeup

解密脚本

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
26
27
28
29
30
31
32
from Crypto.Cipher import AES
from Crypto.Util.Padding import pad
import sys

def AES_decrypt(cipher_text, key):
try:
cipher = AES.new(key, AES.MODE_ECB)
padded_text = cipher.decrypt(cipher_text)
text = unpad(padded_text, AES.block_size)
return text
except:
return None

cipher_text = b"\xe0<Z\xb3\x95\xe2%\xf7\xb1\xc66\xfe\x1d\x12\xcb\xc1[q&q\x9e\x17\xc3;\x02'\xa1m\xc4L\xca\xcdg\x1e\x8a\x97@\xd6y\x02\x0c\xcbO\x91j%4."

found = False
for k in range(1, 33554431):
key_str = str(k).encode('utf-8')
padded_key = pad(key_str, AES.block_size)
plain_text = AES_decrypt(cipher_text, padded_key)
if plain_text is not None:
try:
text = plain_text.decode('utf-8')
if 'flag' in text.lower() or 'ctf' in text.lower() or '{' in text:
print("Found key:", k)
print("Decrypted text:", text)
found = True
break
except UnicodeDecodeError:
pass
if not found:
print("Failed to decrypt. Please check the cipher_text.")

注:因为r是25位素数,最大不超过2的25次方33,554,432,所以key = N % r的最大值是33,554,431

感谢出题人审阅 辛苦了


文章作者: 企鹅主人
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 企鹅主人 !
  目录