当前位置: 代码迷 >> 综合 >> BUUCTF_Crypto_[BJDCTF2020]这是base、、
  详细解决方案

BUUCTF_Crypto_[BJDCTF2020]这是base、、

热度:66   发布时间:2023-12-02 16:05:26.0

题目:

重新定义了base64

下面给了密文

通过base64的原理写出代码:

import libnum
a='FlZNfnF6Qol6e9w17WwQQoGYBQCgIkGTa9w3IQKw'
b=libnum.s2b(a)+'0000'
c=''
d={0: 'J', 1: 'K', 2: 'L', 3: 'M', 4: 'N', 5: 'O', 6: 'x', 7: 'y', 8: 'U', 9: 'V', 10: 'z', 11: 'A', 12: 'B', 13: 'C', 14: 'D', 15: 'E', 16: 'F', 17: 'G', 18: 'H', 19: '7', 20: '8', 21: '9', 22: 'P', 23: 'Q', 24: 'I', 25: 'a', 26: 'b', 27: 'c', 28: 'd', 29: 'e', 30: 'f', 31: 'g', 32: 'h', 33: 'i', 34: 'j', 35: 'k', 36: 'l', 37: 'm', 38: 'W', 39: 'X', 40: 'Y', 41: 'Z', 42: '0', 43: '1', 44: '2', 45: '3', 46: '4', 47: '5', 48: '6', 49: 'R', 50: 'S', 51: 'T', 52: 'n', 53: 'o', 54: 'p', 55: 'q', 56: 'r', 57: 's', 58: 't', 59: 'u', 60: 'v', 61: 'w', 62: '+', 63: '/', 64: '='}
f=[]
g=''
for i in range (len(a)):for j in range (len(d)):if a[i] == d[int(j)]:c += '{:06}'.format(int(str(bin(j)).replace('0b','')))j+=1
for i in range(0,len(c),8):f.append('{:<08}'.format(c[i:i+8]))
for i in range(0,len(f)):g += libnum.b2s(f[i])
print(g)

先将密文的每一个字符通过给出的新的base64定义转换为其代表的十进制数再转换成二进制数,二进制数不足6位的像前面补0,再每8位一组分开,不足8位的后面补0,再通过libnum.b2s()函数将二进制数转换为字符串得到flag

  相关解决方案