[南邮OJ](密码学)n次Base64


题目链接:

n次base64 200
依然是base64不过。。。编码次数有点多请用python解吧~
地址:密文地址


分析:
没有疑问 , 题目中提示已经说明了一切
使用Python写一个循环来解密
这里笔者将Base64的递归解密封装成了一个函数 , 以后如果需要就可以直接拿来用

# coding:utf8

import base64

def repeatedb64decode(ciphertext, times):
    '''
    功能 : 
        指定次数解密Base64
    参数 : 
        ciphertext : 密文
        times : 次数
    返回 : 
        返回将密文解密times次得到的明文
    备注 : 
        当用户输入次数大于密文加密次数时候 , 只会解密到最终的明文 , 而不会一直进行解密
    '''
    for i in range(times):
        try:
            ciphertext = base64.b64decode(ciphertext)
        except Exception:
            return ciphertext
    return ciphertext

def recursive64decode(ciphertext):
    '''
    功能 : 
        递归解密Base64
    参数 : 
        ciphertext : 密文
    返回 : 
        返回彻底解密得到的明文
    '''
    while True:
        try:
            ciphertext = base64.b64decode(ciphertext)
        except Exception:
            return ciphertext

def repeatedb64encode(plaintext , times):
    '''
    功能 : 
        指定次数加密Base64
    参数 : 
        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
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容