刷题笔记:[2021GKCTF]QQQQT


前言

关键词:[base58|加密算法题|密码学|常见加密]

当时没做出来,贴贴wp里的内容

题解

import binascii


def b58encode(tmp: str) -> str:
    tmp = list(map(ord, tmp))
    temp = tmp[0]
    base58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
    for i in range(len(tmp)-1):
        temp = temp * 256 + tmp[i+1]
    tmp = []
    while True:
        tmp.insert(0, temp % 58)
        temp = temp // 58
        if temp == 0:
            break
    temp = ""
    for i in tmp:
        temp += base58[i]
    return temp


def b58decode(tmp: str) -> str:
    base58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
    temp = []
    for i in tmp:
        temp.append(base58.index(i))
    tmp = temp[0]
    for i in range(len(temp)-1):
        tmp = tmp * 58 + temp[i+1]
    # unhexlify()=a2b_hex(),将16进制数转化为相应ascii码字符串
    return binascii.unhexlify(hex(tmp)[2:].encode("utf-8")).decode("UTF-8")


cmp = "56fkoP8KhwCf3v7CEz"
print('flag{' + b58decode(cmp) + '}')


文章作者: 巡璃
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 巡璃 !
评论
  目录