[HUBUCTF 2022 新生赛]help

1. 收获,学习到了动态调试拿资源

2. 首先,拖进IDA分析代码:

很明显,CreateMap,是创造迷宫的函数,我们if语句里面说明路径是一个54长度的字符串,然后check函数检查路径正确性,CreateMap函数如下,map通过num得到

3、动态调试拿到map

3.1 ,然后随便输入一个,点击CreateMap中去看数据

记住迷宫是16行16列的,导出来还需要手动调一下:

发现长这样:

由于check函数里v5从15开始,因此起点应该是最后一行那个

4、编写python脚本拿到最短路径用md5加密就好,使用bfs搜索

from collections import deque


def bfs(maze, start, end):
    # 定义四个移动方向
    directions = [(0, 1, 'd'), (1, 0, 's'), (0, -1, 'a'), (-1, 0, 'w')]

    # 队列中的元素是(当前坐标,到达当前坐标的路径)
    queue = deque([(start, [])])

    # 创建集合保存已访问的点
    visited = set()
    visited.add(start)

    while queue:
        # 当前位置和路径
        (x, y), path = queue.popleft()

        for dx, dy, direction in directions:
            # 下一个可能的位置
            next_x, next_y = x + dx, y + dy

            # 如果这个位置在迷宫范围内并且没有被访问过
            if 0 <= next_x < len(maze) and 0 <= next_y < len(maze[0]) and (next_x, next_y) not in visited:
                if maze[next_x][next_y] == 0 or (next_x, next_y) == end:
                    visited.add((next_x, next_y))  # 标记为已访问
                    new_path = path + [direction]  # 新路径添加移动方向

                    # 如果到达终点,则返回路径
                    if (next_x, next_y) == end:
                        return new_path

                    # 否则,将新位置和新路径添加到队列中
                    queue.append(((next_x, next_y), new_path))

    # 如果所有可能都走完了还没找到终点,那么返回 None
    return None


# 定义迷宫
maze = [
[1,   1,   1,   1,   1,   1,   1,   1,   1,   1,   1,   1,   1,   1,   1,   1],
[1,   0,   0,   0,   0,   0,   1,   1,   1,   1,   1,   1,   0,   1,   1,   1],
[1,   0,   1,   1,   1,   0,   1,   1,   1,   1,   1,   1,   0,   1,   1,   1],
[1,   0,   1,   1,   1,   0,   1,   1,   0,   0,   0,   1,   0,   1,   1,   1],
[1,   0,   1,   1,   1,   0,   1,   1,   0,   1,   0,   1,   0,   1,   1,   1],
[1,   0,   1,   1,   1,   0,   0,   0,   0,   1,   0,   1,   0,   1,   1,   1],
[1,   0,   1,   1,   1,   1,   1,   1,   0,   1,   0,   1,   0,   1,   1,   1],
[1,   0,   1,   1,   1,   1,   1,   1,   0,   0,   0,   1,   0,   1,   1,   1],
[1,   0,   1,   1,   1,   1,   1,   1,   1,   0,   1,   1,   0,   1,   1,   1],
[1,   0,   1,   1,   1,   1,   1,   1,   1,   0,   1,   1,   0,   1,   1,   1],
[1,   0,   0,   0,   0,   1,   1,   0,   0,   0,   0,   1,   0,   0,   0,   1],
[1,   1,   1,   1,   0,   1,   1,   1,   1,   0,   1,   1,   0,   1,   0,   1],
[1,   1,   1,   1,   0,   1,   1,   1,   1,   0,   1,   1,   0,   1,   0,   1],
[1,   0,   0,   0,   0,   1,   1,   1,   1,   0,   1,   1,   0,   1,   0,   0],
[1,   0,   1,   1,   1,   1,   1,   1,   1,   0,   0,   0,   0,   1,   1,   1],
[1,   0,   1,   1,   1,   1,   1,   1,   1,   1,   1,   1,   1,   1,   1,   1]
]

# 寻找起点
start = (15,1)
end = (13,15)
# 执行广度优先搜索
path = bfs(maze, start,end)

if path:
    print("Found path:", ''.join(path))
else:
    print("No path found with the exact length of 54.")

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值