当前位置: 首页 > java >正文

逆向常见题目—迷宫类题目

逆向常见题目—迷宫类题目

image-20250505161128011

迷宫(maze)

思路:

1.找到地图(字符串)

2.找到方向(上左下右)

3.找到起点到终点

然后将路径输出即可

特征: 标题,hint为maze 或者 看到字符串###等等

image-20250428102319278

整理字符串为图形.py

(要是不是正方形需要自己输出行和列)

import mathdef arrange_string_to_square():# 获取用户输入的字符串input_str = input("请输入要整理的字符串: ").strip()length = len(input_str)# 检查是否是完美平方数sqrt = math.isqrt(length)if sqrt * sqrt == length:# 是完美平方数,自动确定行列数rows = cols = sqrtprint(f"字符串长度{length}是完美平方数({sqrt}x{sqrt}),自动整理为{sqrt}x{sqrt}的图形。")else:# 不是完美平方数,让用户选择行列数print(f"字符串长度{length}不是完美平方数,请指定行列数。")while True:try:rows = int(input("请输入行数: "))cols = int(input("请输入列数: "))if rows * cols != length:print(f"错误:行数×列数({rows}x{cols}={rows * cols})不等于字符串长度({length})")continuebreakexcept ValueError:print("请输入有效的整数!")# 按行列数整理字符串for i in range(rows):start = i * colsend = start + colsprint(input_str[start:end])# 返回行列数供后续使用return rows, cols# 调用函数
rows, cols = arrange_string_to_square()
请输入要整理的字符串: S #######  ## ####  # #####   ###   #  ####### ##      #######E#
字符串长度64是完美平方数(8x8),自动整理为8x8的图形。
S ######
#  ## ##
##  # ##
###   ##
#   #  #
###### #
#      #
######E#

整理图形到输出路径.py

import math
from collections import dequedef create_grid(input_str, rows=None, cols=None):"""将字符串转换为二维网格"""length = len(input_str)if rows is None or cols is None:sqrt = math.isqrt(length)if sqrt * sqrt == length:rows = cols = sqrtprint(f"字符串长度{length}是完美平方数({sqrt}x{sqrt}),自动整理为{sqrt}x{sqrt}的图形。")else:raise ValueError("字符串长度不是完美平方数,必须指定行列数")if rows * cols != length:raise ValueError(f"行数×列数({rows}x{cols}={rows * cols})不等于字符串长度({length})")grid = []for i in range(rows):start = i * colsend = start + colsgrid.append(list(input_str[start:end]))return griddef print_grid(grid):"""打印网格(不添加额外空格)"""for row in grid:print(''.join(row))print()def find_position(grid, char):"""查找字符在网格中的位置"""for i in range(len(grid)):for j in range(len(grid[0])):if grid[i][j] == char:return (i, j)return Nonedef find_path(grid, start_char, end_char, moves):"""使用BFS算法查找从起点到终点的路径,路径上只能走空格(起点和终点除外)"""start = find_position(grid, start_char)end = find_position(grid, end_char)if not start:raise ValueError(f"起点字符 '{start_char}' 不存在于网格中")if not end:raise ValueError(f"终点字符 '{end_char}' 不存在于网格中")rows = len(grid)cols = len(grid[0]) if rows > 0 else 0directions = {'w': (-1, 0),  # 上's': (1, 0),   # 下'a': (0, -1),  # 左'd': (0, 1)    # 右}queue = deque([(start, [])])visited = set([start])while queue:(x, y), path = queue.popleft()if (x, y) == end:return pathfor move in moves:dx, dy = directions[move]nx, ny = x + dx, y + dy# 检查新位置是否有效if 0 <= nx < rows and 0 <= ny < cols and (nx, ny) not in visited:# 如果是终点,直接可以到达if (nx, ny) == end:return path + [move]# 路径中间必须是空格if grid[nx][ny] == ' ':visited.add((nx, ny))queue.append(((nx, ny), path + [move]))return Nonedef main():input_str = input("请输入要整理的字符串: ").strip()length = len(input_str)try:grid = create_grid(input_str)except ValueError:print(f"字符串长度{length}不是完美平方数,请指定行列数。")while True:try:rows = int(input("请输入行数: "))cols = int(input("请输入列数: "))grid = create_grid(input_str, rows, cols)breakexcept ValueError as e:print(e)print("\n生成的网格:")print_grid(grid)start_char = input("请输入起点字符: ").strip()end_char = input("请输入终点字符: ").strip()moves_input = input("请输入移动指令序列(WASD,如'wasd','上左下右'): ").strip().lower()valid_moves = {'w', 'a', 's', 'd'}moves = [m for m in moves_input if m in valid_moves]if not moves:print("错误: 没有输入有效的移动指令(WASD)")returnpath = find_path(grid, start_char, end_char, moves)if path:print(f"\n从 '{start_char}' 到 '{end_char}' 的路径:")print(''.join(path))  # 修改为直接输出连接后的字符串else:print(f"\n无法从 '{start_char}' 到达 '{end_char}' 使用给定的移动指令")if __name__ == "__main__":main()
请输入要整理的字符串: S #######  ## ####  # #####   ###   #  ####### ##      #######E#
字符串长度64是完美平方数(8x8),自动整理为8x8的图形。生成的网格:
S ######
#  ## ##
##  # ##
###   ##
#   #  #
###### #
#      #
######E#请输入起点字符: S
请输入终点字符: E
请输入移动指令序列(WASD,如'wasd','上左下右'): wasd从 'S' 到 'E' 的路径:
dsdsdsddsdsss进程已结束,退出代码为 0

例题1--NSSCTF--RE6

ida打开

第一步:找到地图

shift+F6查看字符串

image-20250505000445876

点进去,选中,按A排成一行

image-20250505000510671

复制出来

S #######  ## ####  # #####   ###   #  ####### ##      #######E#

发现为64个字符

确认为8x8图形

第二步:找到方向

Tab查看汇编

image-20250504235255845

119 115 97 100

image-20250504235343656

经典是上下左右 wsad

第三步:确认起点终点

8个一行

S #######  ## ####  # #####   ###   #  ####### ##      #######E#

确认S为起点,E为终点

输入整理字符串到输出路径.py即可

请输入要整理的字符串: S #######  ## ####  # #####   ###   #  ####### ##      #######E#
字符串长度64是完美平方数(8x8),自动整理为8x8的图形。生成的网格:
S ######
#  ## ##
##  # ##
###   ##
#   #  #
###### #
#      #
######E#请输入起点字符: S
请输入终点字符: E
请输入移动指令序列(WASD,如'wasd','上左下右'): wasd从 'S' 到 'E' 的路径:
dsdsdsddsdsss进程已结束,退出代码为 0

image-20250505000606457

http://www.xdnf.cn/news/4106.html

相关文章:

  • 《繁花》投资、交易启示及思考
  • USB资料摘录for后期,bus hound使用
  • 【ROS2】 QoS(服务质量)介绍
  • 信息安全基石:加解密技术的原理、应用与未来
  • 关于string类的构造函数
  • 【C++进阶十】多态深度剖析
  • Paramiko源码深入解析
  • 2025年PMP 学习四
  • Monster Hunter Rise 怪物猎人 崛起 [DLC 解锁] [Steam] [Windows SteamOS]
  • MySQL基础关键_008_DDL 和 DML(一)
  • linux、window安装部署nacos
  • STC单片机与淘晶驰串口屏通讯例程之02【HDMI数据处理】
  • LangChain构建大模型应用之Chain
  • APP 设计中的色彩心理学:如何用色彩提升用户体验
  • 模型训练实用之梯度检查点
  • 二重指针和二维数组
  • 深入理解 Cortex-M3 的内核寄存器组
  • 学习笔记msp430f5529lp
  • AI向量检索
  • 【前缀和】连续数组
  • 支持图文混排的Gemini Next Chat
  • Linux 系统下VS Code python环境配置!
  • GPU性能加速的隐藏魔法:Dual-Issue Warp Schedule全解析
  • 国内短剧 vs. 海外短剧系统:如何选择?2025年深度对比与SEO优化指南
  • 高并发内存池------threadcache
  • WebService的学习
  • 电子邮件相关协议介绍
  • NetSuite 2025.1 学习笔记
  • Java基础学完,继续深耕(0505)Linux 常用命令
  • TS 类class修饰符