首页
社区
课程
招聘
KCTF2022春季赛 第二题 末日邀请
2022-5-11 18:25 15504

KCTF2022春季赛 第二题 末日邀请

2022-5-11 18:25
15504
flag分为4段, 记为[part1][part2][part3][part4]
part1: 未知, 长度为3
part2: KCTF
part3: 长度为9
part4: 无解, 长度为0
crc32(flag)==0xF52E0765

part3(摘自wikipedia)
Arrange the digits 1 to 9 in order so that 
the first two digits form a multiple of 2, 
the first three digits form a multiple of 3, 
the first four digits form a multiple of 4 etc. 
and finally the entire number is a multiple of 9.
The solution to the problem is a nine-digit polydivisible number 
with the additional condition that it contains the digits 1 to 9 exactly once each


脚本

import itertools
import string


CRC32_TAB = [0] * 256


def crc32_init():
    global CRC32_TAB
    c = 0xEDB88320 - 0x100000000
    for i in range(256):
        v = i
        for j in range(8):
            if (v & 1) != 0:
                v = (v >> 1) ^ c
            else:
                v = v >> 1
        CRC32_TAB[i] = v
    return


def crc32(data: bytes) -> int:
    v = -1
    for b in data:
        v = (CRC32_TAB[(v ^ b) & 0xFF] ^ (v >> 8))
    return ~v & 0xFFFFFFFF


def test1():
    crc32_init()
    cs = string.printable
    for ent in itertools.product(cs, repeat=3):
        part1 = ''.join(ent)
        sn = part1 + 'KCTF381654729'
        if crc32(sn.encode()) == 0xF52E0765:
            print('flag: %s' % sn)
            break
    return


def test3():
    cs = '123456789'
    for ent in itertools.permutations(cs, 9):
        s = ''.join(ent)
        ok = True
        for i in range(1, 10):
            v = int(s[:i])
            if (v % i) != 0:
                ok = False
                break
        if ok:
            print(s)
            # 381654729
            break
    return


def test():
    test1()
    # test3()
    return


test()
# flag: 421KCTF381654729



[培训]内核驱动高级班,冲击BAT一流互联网大厂工 作,每周日13:00-18:00直播授课

收藏
点赞2
打赏
分享
最新回复 (1)
游客
登录 | 注册 方可回帖
返回