南京邮电大学CTF-密码学-mixed_base64

题目如下:

南京邮电大学CTF-密码学-mixed_base64_第1张图片

1.先把code.txt保存为一个文件

2.加密过程:

    十次加密,每一次在base16,32,64中随机选择一种加密

3.解密过程:

    用python直接尝试爆破

解密代码:

#*****题目:多重base64加密
#*****python破解代码

import base64

def decode_mix_base64(b):
    a = b
   # print a
    i = 0
    while True:
        i = i+1
        print i
        #base16
        try:           
           c = base64.b16decode(a)
           a = c
           print('using base16 decode sucess.....')
           continue
        except:
            print ('using base16 decode failuer.....')
            pass      
        #base32
        try:
           c = base64.b32decode(a)
           a = c
           print('using base32 decode sucess.....')
           continue
        except:
            print ('using base32 decode failuer.....')
            pass
         #base64
        try:  
           c = base64.b64decode(a)
           a = c
           print('using base64 decode sucess.....')
           continue
        except:
             print ('using base64 decode failuer.....')
             pass     
        break
    print a
            
def main():
    a = open('ctf_code_base64.txt')
    try:
        b = a.read()
    finally:
        a.close()
    #while True:
    try:
            #b = base64.b64decode(b)
        decode_mix_base64(b)
    except:
        print ('Finish!*********')
        #break
    
    
if __name__ == '__main__':
    main()

运行程序破解flag

南京邮电大学CTF-密码学-mixed_base64_第2张图片

ok,完成,拿到flag

你可能感兴趣的:(CTF,Python)