Created
August 22, 2020 10:46
-
-
Save 0awawa0/cfe1aa8199c4aed276520cb5e2a3bf06 to your computer and use it in GitHub Desktop.
This file contains 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 | |
from morse_decode import morse_decode | |
from zipfile import ZipFile | |
from os import chdir, remove, rmdir | |
from shutil import copyfile, rmtree | |
def parse_image_to_morse(pixels, width, height, space_color, sign_color): | |
code = "" | |
for x in range(1, height, 2): | |
char_code = "" | |
counter = 0 | |
for y in range(1, width): | |
if rgb_to_int(pixels[y, x]) == sign_color: | |
counter += 1 | |
else: | |
if counter == 3: | |
char_code += "-" | |
if counter == 1: | |
char_code += "." | |
counter = 0 | |
code += char_code + " " | |
return code | |
def rgb_to_int(color): | |
return (color[0] << 8 | color[1]) << 8 | color[2] | |
for i in range(999, 0, -1): | |
image = Image.open("pwd.png") | |
pixels = image.load() | |
space_color = rgb_to_int(pixels[0, 0]) | |
sign_color = rgb_to_int(pixels[1, 1]) | |
password = morse_decode(parse_image_to_morse(pixels, image.width, image.height, space_color, sign_color)) | |
print(f"{i} Password is: {password}") | |
ZipFile(f"flag_{i}.zip").extractall(pwd=password.encode()) | |
remove("pwd.png") | |
remove(f"flag_{i}.zip") | |
copyfile(f"./flag/flag_{i - 1}.zip", f"./flag_{i - 1}.zip") | |
copyfile("./flag/pwd.png", "./pwd.png") | |
rmtree("./flag") | |
image.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment