[南郵OJ](密碼學)n次Base64


題目鏈接:

n次base64 200
依然是base64不過。。。編碼次數(shù)有點多請用python解吧~
地址:密文地址


分析:
沒有疑問 , 題目中提示已經(jīng)說明了一切
使用Python寫一個循環(huán)來解密
這里筆者將Base64的遞歸解密封裝成了一個函數(shù) , 以后如果需要就可以直接拿來用

# coding:utf8

import base64

def repeatedb64decode(ciphertext, times):
    '''
    功能 : 
        指定次數(shù)解密Base64
    參數(shù) : 
        ciphertext : 密文
        times : 次數(shù)
    返回 : 
        返回將密文解密times次得到的明文
    備注 : 
        當用戶輸入次數(shù)大于密文加密次數(shù)時候 , 只會解密到最終的明文 , 而不會一直進行解密
    '''
    for i in range(times):
        try:
            ciphertext = base64.b64decode(ciphertext)
        except Exception:
            return ciphertext
    return ciphertext

def recursive64decode(ciphertext):
    '''
    功能 : 
        遞歸解密Base64
    參數(shù) : 
        ciphertext : 密文
    返回 : 
        返回徹底解密得到的明文
    '''
    while True:
        try:
            ciphertext = base64.b64decode(ciphertext)
        except Exception:
            return ciphertext

def repeatedb64encode(plaintext , times):
    '''
    功能 : 
        指定次數(shù)加密Base64
    參數(shù) : 
        plaintext : 明文
        times : 密文
    返回 : 
        將plaintext加密times次得到的密文
    備注 : 
        加密不存在異常拋出的問題
    '''
    for i in range(times):
        plaintext = base64.b64encode(plaintext)
    return plaintext

ciphertext = ""

print recursive64decode(ciphertext)

答案:
nctf{please_use_python_to_decode_base64}


知識點:

  1. Python
  2. Base64
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容