[Reverse] PUZZLE - Cew xp0int Posted on Apr 29 2021 先用修改版的base64算法decode输入,然后以decode_input为操作步骤,重排九宫... ``` 初始 4 0 3 7 2 6 8 1 5 完成 1 2 3 4 5 6 7 8 0 操作方法 '2'将0同上交换 '8'将0同下交换 '6'将0同左交换 '4'将0同右交换 ``` ``` # astar 算法 #coding=utf-8 from __future__ import print_function import copy def showMap(array2d): for x in xrange(0, 3): for y in xrange(0, 3): print(array2d[x][y], end='') print(" ") print("--------") return def move(array2d, srcX, srcY, drcX, drcY): temp = array2d[srcX][srcY] array2d[srcX][srcY] = array2d[drcX][drcY] array2d[drcX][drcY] = temp return array2d def getStatus(array2d): y = 0 for i in xrange(0, 3): for j in xrange(0, 3): for m in xrange(0, i+1): for n in xrange(0, j): if array2d[i][j] > array2d[m][n]: y += 1 return y class Node: def __init__(self, array2d, g = 0, h = 0): self.array2d = array2d self.father = None self.g = g self.h = h def setH(self, endNode): for x in xrange(0, 3): for y in xrange(0, 3): for m in xrange(0, 3): for n in xrange(0, 3): if self.array2d[x][y] == endNode.array2d[m][n]: self.h += abs(x*y - m*n) def setG(self, g): self.g = g def setFather(self, node): self.father = node def getG(self): return self.g class A: """ A 算法 python 2.7 """ def __init__(self, startNode, endNode): #开放列表 self.openList = [] #封闭列表 self.closeList = [] #起点 self.startNode = startNode #终点 self.endNode = endNode #当前处理的节点 self.currentNode = startNode #最后生成的路径 self.pathlist = [] #step步 self.step = 0 return def getMinFNode(self): nodeTemp = self.openList[0] for node in self.openList: if node.g + node.h < nodeTemp.g + nodeTemp.h: nodeTemp = node return nodeTemp def nodeInOpenlist(self,node): for nodeTmp in self.openList: if nodeTmp.array2d == node.array2d: return True return False def nodeInCloselist(self,node): for nodeTmp in self.closeList: if nodeTmp.array2d == node.array2d: return True return False def endNodeInOpenList(self): for nodeTmp in self.openList: if nodeTmp.array2d == self.endNode.array2d: return True return False def getNodeFromOpenList(self,node): for nodeTmp in self.openList: if nodeTmp.array2d == node.array2d: return nodeTmp return None def searchOneNode(self,node): if self.nodeInCloselist(node): return gTemp = self.step if self.nodeInOpenlist(node) == False: node.setG(gTemp) node.setH(self.endNode) self.openList.append(node) node.father = self.currentNode else: nodeTmp = self.getNodeFromOpenList(node) if self.currentNode.g + gTemp < nodeTmp.g: nodeTmp.g = self.currentNode.g + gTemp nodeTmp.father = self.currentNode return def searchNear(self): flag = False for x in xrange(0, 3): for y in xrange(0,3): if self.currentNode.array2d[x][y] == 0: flag = True break if flag == True: break self.step += 1 if x - 1 >= 0: arrayTemp = move(copy.deepcopy(self.currentNode.array2d), x, y, x - 1, y) self.searchOneNode(Node(arrayTemp)) if x + 1 < 3: arrayTemp = move(copy.deepcopy(self.currentNode.array2d), x, y, x + 1, y) self.searchOneNode(Node(arrayTemp)) if y - 1 >= 0: arrayTemp = move(copy.deepcopy(self.currentNode.array2d), x, y, x, y - 1) self.searchOneNode(Node(arrayTemp)) if y + 1 < 3: arrayTemp = move(copy.deepcopy(self.currentNode.array2d), x, y, x, y + 1) self.searchOneNode(Node(arrayTemp)) return def start(self): startY = getStatus(self.startNode.array2d) endY = getStatus(self.endNode.array2d) if startY%2 != endY%2: return False self.startNode.setH(self.endNode) self.startNode.setG(self.step) self.openList.append(self.startNode) while True: self.currentNode = self.getMinFNode() self.closeList.append(self.currentNode) self.openList.remove(self.currentNode) self.step = self.currentNode.getG() self.searchNear() if self.endNodeInOpenList(): nodeTmp = self.getNodeFromOpenList(self.endNode) while True: self.pathlist.append(nodeTmp) if nodeTmp.father != None: nodeTmp = nodeTmp.father else: return True elif len(self.openList) == 0: return False elif self.step > 30: return False return True def showPath(self): for node in self.pathlist[::-1]: showMap(node.array2d) ``` ``` import astar if __name__ == '__main__': a = astar.A(astar.Node([[4,0,3],[7,2,6],[8,1,5]]), astar.Node([[1,2,3],[4,5,6],[7,8,0]])) print "A start:" if a.start(): a.showPath() else: print "no way" ''' A start: 403 726 815 -------- 423 706 815 -------- 423 716 805 -------- 423 716 850 -------- 423 710 856 -------- 420 713 856 -------- 402 713 856 -------- 412 703 856 -------- 412 753 806 -------- 412 753 086 -------- 412 053 786 -------- 012 453 786 -------- 102 453 786 -------- 120 453 786 -------- 123 450 786 -------- 123 456 780 -------- path: 884226886224488 ''' ``` ``` t = str.maketrans("STUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/ABCDEFGHIJKLMNOPQR", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/") print(b64encode(b'884226886224488').decode().translate(t)) # 8xOi6R2k8xOk6R2i7xOm ``` flag{8xOi6R2k8xOk6R2i7xOm} 打赏还是打残,这是个问题 赏 Wechat Pay Alipay [Pwn] pwn1 - cpt.shao [Reverse] PE - Cew
没有帐号? 立即注册