欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

2020DASCTF七月赛-bulls**t

程序员文章站 2022-05-08 09:13:05
题目:def pairing(a,b): shell = max(a, b) step = min(a, b) if step == b: flag = 0 else: flag = 1 return shell ** 2 + step * 2 + flagdef encrypt(message): res = '' for i in range(0,len(message),2): res +=...

题目:

def pairing(a,b):
    shell = max(a, b)
    step = min(a, b)
    if step == b:
        flag = 0
    else:
        flag = 1
    return shell ** 2 + step * 2 + flag

def encrypt(message):
    res = ''
    for i in range(0,len(message),2):
        res += str(pairing(ord(message[i]),ord(message[i+1])))
        res+=' '
    return res

print(encrypt(flag))
# 1186910804152291019933541010532411051999082499105051010395199519323297119520312715722

题目中把flag中的字符两个一组加密成一个数字,最后进行拼接

由于flag中只含有数字字母和大括号,我们可以算出每组的数字中
最小约为ord('0')**2+ord('0')*2=2400;
最大约为ord('}')**2+ord('}')*2=15875;
则从头开始,以’1‘开头的往下取5位,以其他数字开头的往下取4位,把数字分开

11869 10804 15229 10199 3354 10105 3241 10519 9908 2499 10505 10103 9519 9519 3232 9711 9520 3127 15722

直接爆破flag

dic='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ{}'

def pairing(a,b):
    shell = max(a, b)
    step = min(a, b)
    if step == b:
        flag = 0
    else:
        flag = 1
    return shell ** 2 + step * 2 + flag

l='11869 10804 15229 10199 3354 10105 3241 10519 9908 2499 10505 10103 9519 9519 3232 9711 9520 3127 15722'.split(' ')

def solve():
    c=0
    while(1):
        for i in dic:
            for j in dic:
                if pairing(ord(i),ord(j))==int(l[c]):
                    c+=1
                    print(i,end='')
                    print(j,end='')
                    if c==19:
                        return 0
solve()

本文地址:https://blog.csdn.net/qq_45819626/article/details/107582547