プログラム task.py と、その出力 output.txt が与えられた。
task.py は以下の処理をするものだった。
flag.txt を読み込み、先頭が CakeCTF{ であることを確かめる。flag.txt の内容を数値に変換する。この数値を m とする。c を0に初期化する。m の下位ビットから順にXORをし、得られたビットを c の最下位に結合する。c の値を出力する。
このとき、m の最上位のバイトのうち連続する上位の0のビットについては、結合処理が行われない。
また、出力されるc の値には、最上位に何個0が結合されたかの情報は含まれない。
そこで、まず以下のプログラムを用い、CakeCTF{ を入力した時の出力が与えられたものになるような初期値を
m の最上位のバイト (最後のバイト) は改行 (0x0a) であり、結合処理の対象にならない上位の0は4ビットであると仮定すると、適切な初期値が求まった。
A program task.py and its output output.txt were given.
What
flag.txt and make sure the prefix of its contents is CakeCTF{.flag.txt to an integer m.c to zero.m (lower bit first),
and append the result bits to the lowest side of c.c.
In this operation, the appendeng doesn't happen for the top consecutive bits with value 0 in the topmost byte of m.
Moremover, the value of c in the output doesn't contain information about how many zeros are concatenated to the highest part.
I used this program to obtain the initial value to make the output to be what is given when the input is CakeCTF{.
I obtained the proper initial value by assuming the hightest byte (the last byte) of m is a newline character (0x0a)
and that there are 4 consequtive top bits not for appending.
以下のプログラムに得られた初期値を与えて実行し、出力に
I obtained the flag by executing this program with the obtained initial value and applying "From Hex" to the output via