-
-
[原创]KCTF 2024 第二题 WriteUp
-
发表于: 2024-8-16 14:13 4063
-
根据代码要求,flag长度为70,形式为flag{...},中间的64个字符分为两部分,第一部分56个字符用于解数独,第二部分8个字符用于走迷宫
通过文件偏移dump出要求解的9x9数独,0x0F为需要填入的位置,从左到右、从上到下依次填入1-9数字
def
is_safe(board, row, col, num):
for
x
in
range
(
9
):
if
board[row][x]
=
=
num:
return
False
if
board[x][col]
=
=
num:
return
False
if
board[
3
*
(row
/
/
3
)
+
x
/
/
3
][
3
*
(col
/
/
3
)
+
x
%
3
]
=
=
num:
return
False
return
True
def
solve_sudoku(board):
for
row
in
range
(
9
):
for
col
in
range
(
9
):
if
board[row][col]
=
=
0x0F
:
for
num
in
range
(
1
,
10
):
if
is_safe(board, row, col, num):
board[row][col]
=
num
if
solve_sudoku(board):
return
True
board[row][col]
=
0x0F
return
False
return
True
def
print_board(board):
for
row
in
board:
print
(
" "
.join(
str
(val)
if
val !
=
0x0F
else
"."
for
val
in
row))
board
=
[
[
0x0F
,
0x0F
,
0x02
,
0x0F
,
0x0F
,
0x07
,
0x0F
,
0x0F
,
0x0F
],
[
0x0F
,
0x06
,
0x0F
,
0x09
,
0x0F
,
0x0F
,
0x04
,
0x0F
,
0x0F
],
[
0x0F
,
0x09
,
0x0F
,
0x02
,
0x05
,
0x0F
,
0x0F
,
0x0F
,
0x03
],
[
0x0F
,
0x0F
,
0x0F
,
0x04
,
0x0F
,
0x0F
,
0x01
,
0x0F
,
0x0F
],
[
0x07
,
0x03
,
0x0F
,
0x0F
,
0x06
,
0x0F
,
0x0F
,
0x0F
,
0x0F
],
[
0x0F
,
0x0F
,
0x09
,
0x05
,
0x03
,
0x0F
,
0x0F
,
0x06
,
0x0F
],
[
0x0F
,
0x0F
,
0x06
,
0x03
,
0x04
,
0x0F
,
0x0F
,
0x07
,
0x0F
],
[
0x08
,
0x0F
,
0x0F
,
0x0F
,
0x0F
,
0x0F
,
0x0F
,
0x0F
,
0x09
],
[
0x0F
,
0x0F
,
0x0F
,
0x0F
,
0x0F
,
0x0F
,
0x0F
,
0x05
,
0x0F
],
]
if
solve_sudoku(board):
print_board(board)
else
:
print
(
"No solution exists"
)
def
is_safe(board, row, col, num):
for
x
in
range
(
9
):
if
board[row][x]
=
=
num:
return
False
if
board[x][col]
=
=
num:
return
False
if
board[
3
*
(row
/
/
3
)
+
x
/
/
3
][
3
*
(col
/
/
3
)
+
x
%
3
]
=
=
num:
return
False
return
True
def
solve_sudoku(board):
for
row
in
range
(
9
):
for
col
in
range
(
9
):
if
board[row][col]
=
=
0x0F
:
for
num
in
range
(
1
,
10
):
if
is_safe(board, row, col, num):
board[row][col]
=
num
if
solve_sudoku(board):
return
True
board[row][col]
=
0x0F
return
False
return
True
def
print_board(board):
for
row
in
board:
print
(
" "
.join(
str
(val)
if
val !
=
0x0F
else
"."
for
val
in
row))
[招生]科锐逆向工程师培训(2024年11月15日实地,远程教学同时开班, 第51期)
赞赏
他的文章
看原图
赞赏
雪币:
留言: