0xGame 2024 [Week 2] 報告哈基米

akaashi_keiji發表於2024-11-04

0xGame 2024 [Week 2] 報告哈基米

新知識:Tupper(塔珀自指公式);Arnold Cat(貓對映)

下載檔案是一個png圖片,010開啟檢視

發現是倒著的pk

圖片2

轉一下儲存為zip檔案,開啟後是一個txt檔案

圖片3

有兩個地方有提示,一個是十六進位制裡面的Maybe You Need To Kown Arnold Cat?還有一個是txt裡面的Is This Tupper?

去搜一下Tupper是什麼

程式碼急轉彎——Tupper(塔珀自指公式)-CSDN部落格

其程式碼執行出來的圖片就是公式本身,在txt檔案中第一句是倒序,所以我們也將下面的k值進行逆序,下面是在網上找的大佬的程式碼,應該是有三個演算法在裡面,我們就用Tupper一個就好了,把k值丟進去跑一下得到圖片

########################################################################
#
#
#                    Tupper’s Self-Referential Formula
#                             Tupper.py
#
#                                MAIN
#
#                 Copyright (C) 2015 Ulrik Hoerlyk Hjort
#
#  Tupper’s Self-Referential Formula is free software;  you can  redistribute it
#  and/or modify it under terms of the  GNU General Public License
#  as published  by the Free Software  Foundation;  either version 2,
#  or (at your option) any later version.
#  Tupper’s Self-Referential Formula is distributed in the hope that it will be
#  useful, but WITHOUT ANY WARRANTY;  without even the  implied warranty
#  of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#  See the GNU General Public License for  more details.
#  You should have  received  a copy of the GNU General
#  Public License  distributed with Yolk.  If not, write  to  the  Free
#  Software Foundation,  51  Franklin  Street,  Fifth  Floor, Boston,
#  MA 02110 - 1301, USA.
########################################################################

from PIL import Image


# Tupper
k1=9489414856877039590479997730148554425666925984049232945604842888420596111937489062065081199094002132087091572191187170308560128611026043144427876131133135794969867759108490917632153891963456295991713868378392769549376070709924497237322046334486274987407067993824142187115870972520417207510521083293280152434558803258138899515603807505064799735152359900010019631133734298562293682916239050320580346316026460860919542540955914826806059123630945216006606268974979135253968165822806241305783300650874506602000048154282039485531804337171305656252


# Pacman
# k2=144520248970897582847942537337194567481277782215150702479718813968549088735682987348888251320905766438178883231976923440016667764749242125128995265907053708020473915320841631792025549005418004768657201699730466383394901601374319715520996181145249781945019068359500510657804325640801197867556863142280259694206254096081665642417367403946384170774537427319606443899923010379398938675025786929455234476319291860957618345432248004921728033349419816206749854472038193939738513848960476759782673313437697051994580681869819330446336774047268864


# Euler
# k3=2352035939949658122140829649197960929306974813625028263292934781954073595495544614140648457342461564887325223455620804204796011434955111022376601635853210476633318991990462192687999109308209472315419713652238185967518731354596984676698288025582563654632501009155760415054499960

# Assign k1,k2, k3 to k to get desired image
k = k1
width = 106
height = 17
scale = 5

fname = "foo"
image  = Image.new("RGB", (width, height),(255, 255, 255))

for x in range (width):
    for y in range (height):
        if ((k+y)//17//2**(17*int(x)+int(y)%17))%2 > 0.5:
            # Image need to be flipped vertically - therefore y = height-y-1
            image.putpixel((x, height-y-1), (0,0,0))


#scale up image
image = image.resize((width*scale,height*scale))
image.save(fname+".png")

圖片1

看大括號的位置,這應該是flag的後半段

找Arnold Cat是個什麼東西

數學中,阿諾德貓對映是一種從環面到自身的混沌對映,以弗拉基米爾·阿諾德的名字命名,他於 20 世紀 60 年代使用貓的影像展示了它的效果,因此得名。該圖的一個特點是影像在變換過程中看似隨機化,但經過若干步驟後又恢復到原始狀態。貓的原始影像在變換的第一次迭代中被剪下然後重新包裹。經過幾次迭代後,生成的影像看起來相當隨機或無序,但經過進一步的迭代後,影像似乎有了進一步的秩序——貓的幽靈般的影像、以重複結構排列的多個較小的副本,甚至是原始影像的顛倒副本——並最終恢復到原始影像。

發現最初的圖片看起來非常無序,應該是經過了貓對映(https://github.com/zhanxw/cat github程式碼)(https://www.jasondavies.com/catmap/ 線上網站)

不知道咋回事網站和程式碼執行後都得不到原圖,看起來還是很無序

卡死在這了

最後看了大佬的wp,太強了,指令碼一執行直接出來了,放一下指令碼

from PIL import Image

img = Image.open('mijiha.png')
if img.mode == "P":
    img = img.convert("RGB")
assert img.size[0] == img.size[1]
dim = width, height = img.size

st = 1
a = 35
b = 7
for _ in range(st):
    with Image.new(img.mode, dim) as canvas:
        for nx in range(img.size[0]):
            for ny in range(img.size[0]):
                y = (ny - nx * a) % width
                x = (nx - y * b) % height
                canvas.putpixel((y, x), img.getpixel((ny, nx)))
canvas.show()
canvas.save('result.png')

得到圖片

result

得到flag前半段,題解

總結:遇到了兩個從來沒有見過的演算法,算是長了見識

相關文章