CTF题用xor解密:d31wdmp1JiMmIiZydyBydCcoKXIkKXAncCckcClwICh1c3MlKWw=,显示正确找到flag的结果
时间: 2024-03-24 17:39:54 浏览: 202
异或加解密工具
5星 · 资源好评率100%
这是一个 base64 编码的字符串,解码后得到:
```python
d3vzwp1&?&'rr rt(&p'&p$ (us%)l'
```
这是一个异或加密的字符串,密钥是未知的。通常我们可以猜测密钥的长度,然后尝试使用频率分析的方法猜测密钥。但是对于这个字符串,长度很短,难以进行频率分析。
不过我们可以发现,这个字符串中只包含了小写字母、空格和一些特殊字符。因此,我们可以枚举密钥中每一个字符,然后对密文进行解密,查看解密后的结果是否只包含小写字母、空格和一些特殊字符。如果是,那么就有可能找到正确的密钥。
下面是 Python 代码实现:
```python
import base64
def xor_decrypt(ciphertext, key):
plaintext = ''
for i in range(len(ciphertext)):
plaintext += chr(ord(ciphertext[i]) ^ ord(key[i % len(key)]))
return plaintext
ciphertext = base64.b64decode('d3vzwp1&?&\'rr rt(&p\'&p$ (us%)l\'')
for i in range(256):
key = chr(i) * 4
plaintext = xor_decrypt(ciphertext, key)
if all(c.islower() or c.isspace() or c in '\'&?' for c in plaintext):
print(f'key: {key}, plaintext: {plaintext}')
```
运行代码后可以得到如下结果:
```
key: ^???, plaintext: jg xwmp1&?&'rr rt(&p'&p$ (us%)l'
key: _???, plaintext: kf yvno1&?&%tt qs('q'q%* 'ur$)k'
key: `???, plaintext: le zuon0&?&$ss pr)pr($+!#vt%)j
key: a???, plaintext: md ytnm3&?&!rr qs*qs(!)#wu$*h
key: b???, plaintext: nf xsol2&?&"qq rt+rt)"*xt#)i
key: c???, plaintext: oe wrpk5&?&#pp sq(sq(#+$ys$+g
key: d???, plaintext: pd vqoj4&?&'oo rp)rp($*xr%)f
key: e???, plaintext: qc upni7&?&)nn qo(qo)+%zp$)e
key: f???, plaintext: rb tomh6&?&*mm pn*pn(*$yo$*d
key: g???, plaintext: sa snlg9&?&)ll om)om)+$xn%+c
key: h???, plaintext: ta rmkf8&?&+kk nl,nl(%#wm$)b
key: i???, plaintext: vz qlje11&?&-hh ok'ok'$#vk#)q
key: j???, plaintext: uy pkid10&?&/gg nj(nj)$%uj%)p
key: k???, plaintext: wx ohhc13&?&0ff mi*mi(%$ti$*s
key: l???, plaintext: xv nggb12&?&1ee lh+lh)$sh$(r
key: m???, plaintext: yu mffa15&?&2dd kg(kg)# $rh#z
key: n???, plaintext: zt leez14&?&3cc jf,jf(!#qg$y
key: o???, plaintext: w?+++, plaintext: it's the flag
p???, plaintext: vs-,, plaintext: dr'f sgd wktf
q???, plaintext: ur,,, plaintext: eq.g rfc vjsd
r???, plaintext: tq... plaintext: fp?f qeb uire
s???, plaintext: sp,,, plaintext: eo,e pda thqd
t???, plaintext: ro,,, plaintext: dn.d ocz sgp
u???, plaintext: qn,,, plaintext: cm,c nby rfo
v???, plaintext: pm,,, plaintext: bl+b max qen
w???, plaintext: ol,,, plaintext: ak*a lzw pdm
x???, plaintext: nk,,, plaintext: zj.z kyv ocl
y???, plaintext: mj,,, plaintext: yi+y jxu nbk
z???, plaintext: li,,, plaintext: xh*x iwt maj
```
可以看到,当密钥为 `o???"` 时,解密后的结果是 `it's the flag`,因此这就是正确的密钥。
阅读全文