-
-
KCTF2022春季赛 第二题 末日邀请
-
2022-5-11 18:25 10931
-
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
赞赏
他的文章
KCTF2022春季赛 第三题 石像病毒
4438
KCTF2022春季赛 第二题 末日邀请
10932
KCTF2021秋季赛 第二题 迷失丛林
13129
KCTF2020秋季赛 第十题 终焉之战
6570
KCTF2020秋季赛 第九题 命悬一线
4739