Last active
March 1, 2021 21:41
-
-
Save MilyMilo/d30b84de8906580ec8f6d69866655307 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Loading fibonacci | |
fib_nums = [] | |
with open("fib.txt", "r+") as fib: | |
lines = fib.readlines() | |
for line in lines: | |
fib_nums.append(int(line.strip())) | |
# Loading bytes | |
kipod_bytes = [] | |
with open("out.split.txt", "r+") as kipod_file: | |
kipod_lines = kipod_file.readlines() | |
for kipod_line in kipod_lines: | |
kipod_bytes.append(kipod_line.strip()) | |
# Some key (marking) chars | |
k_boi = "01001011" | |
a_boi = "01000001" | |
f_boi = "01000110" | |
curly_boi = "01111011" | |
closing_boi = "01111101" | |
# Convert bit string to an ascii char | |
def bits2ascii(bits): | |
bits = int(bits, 2) | |
try: | |
return bits.to_bytes((bits.bit_length() + 7) // 8, 'big').decode() | |
except UnicodeDecodeError: | |
return "" | |
# Create a string from chars at indexes from fibonacci sequence | |
# starting at base_offset | |
def make_fibon_string(base_offset): | |
fibon = "" | |
for fib_offset in fib_nums: | |
total_offset = base_offset + fib_offset | |
char = kipod_bytes[total_offset] | |
fibon += char | |
if char == closing_boi: | |
break | |
flag = bits2ascii(fibon) | |
if flag.startswith("KAF{") and flag.endswith("}"): | |
return flag | |
return "" | |
for byte_idx in range(len(kipod_bytes)): | |
byte = kipod_bytes[byte_idx] | |
if byte == k_boi: | |
# scan next following fib bytes from current position | |
for fib_idx in range(len(fib_nums)): | |
try: | |
next_byte_p0 = kipod_bytes[byte_idx + | |
fib_nums[fib_idx]] # fib(n) | |
next_byte_p1 = kipod_bytes[byte_idx + | |
fib_nums[fib_idx + 1]] # fib(n+1) | |
# Check if the next bytes are 'A' and 'F' (flag beginning) | |
if next_byte_p0 == a_boi and next_byte_p1 == f_boi: | |
# -1 because byte_idx points at 'K' | |
# and we have to start from before that | |
fibon_str = make_fibon_string(byte_idx - 1) | |
if fibon_str != "": | |
print(f"[+] Found flag? {fibon_str}") | |
except IndexError: | |
# fibonacci offset already overflows kipod_bytes | |
# stop checking this byte | |
break | |
continue |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PIL import Image | |
im = Image.open("dinary.png") | |
pix = im.load() | |
size = im.size | |
rows, cols = size | |
out = "" | |
for i in range(rows): | |
for j in range(cols): | |
r, g, b = pix[j, i] | |
# print(f"pix[{i}, {j}] = [{r}, {g}, {b}]") | |
if r > 122 and g > 122 and b > 122: | |
out += "1" | |
else: | |
out += "0" | |
with open("out.txt", "w+") as out_file: | |
out_file.write(out) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import string | |
marked = [] | |
with open("out.split.txt", "r+") as in_file: | |
for line in in_file.readlines(): | |
line = line.strip("\n").strip(" ") | |
char = int(line, 2) | |
try: | |
new_char = char.to_bytes( | |
(char.bit_length() + 7) // 8, 'big' | |
).decode() | |
except UnicodeDecodeError: | |
new_char = "" | |
new_line = "" | |
if new_char == "" or new_char not in string.printable: | |
new_line = line | |
else: | |
new_line = line + " # " + new_char | |
marked.append(new_line) | |
with open("out.marked.txt", "w+") as out_file: | |
out_file.write("\n".join(marked)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment