2020DASCTF七月赛-bulls**t

题目:

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()

你可能感兴趣的:(CTF,密码学,安全)