Skip to content

Commit

Permalink
i love morse code and bash scripting
Browse files Browse the repository at this point in the history
  • Loading branch information
tsalomon committed Mar 3, 2021
1 parent cdc4c78 commit 8aa6a36
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 0 deletions.
42 changes: 42 additions & 0 deletions morse/m0rsarchive.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash

echo "M0rsarchive HTB Solution Script"
echo "Usage: ./m0rsarchive.sh M0rsarchive.zip morsedecode.py"
echo "[!] Starting in 10 seconds..."
sleep 10

#make a new, clean working directory
mkdir ./flagzips

#move to working dir
cd flagzips

#unzip M0rsarchive.zip
unzip -j -o -P hackthebox ../$1 1> /dev/null

#rename original pwd image
mv pwd.png orig_pwd.png

#backup original pwd image
cp orig_pwd.png pwd_999.png

#unzip -j flattens one dir when extracting
#unzip -o overwrites; useful for testing

for ((i=999;i>=0;i--)); do
unzip -j -o -P $(python3 ../$2 pwd_$i.png) flag_$i.zip 1> /dev/null;
mv pwd.png pwd_$(( $i-1 )).png
clear; echo $((1000 - $i))/1000
done

echo "M0rsarchive HTB Solution Script"

#show flag
cat flag

#clean up
cd ..
rm -r ./flagzips

#one-liner: mv pwd.png pwd_999.png; for i in {999..0}; do unzip -j -P $(python3 morsedecode.py pwd_$i.png) flag_$i.zip; mv pwd.png pwd_$(($i - 1)).png ;done ; cat flag

84 changes: 84 additions & 0 deletions morse/morsedecode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import sys
from PIL import Image

if len(sys.argv) != 2:
print(" did you mean?: python3 morsedecode.py pwd.png")
exit()

filename=sys.argv[1]
image = Image.open(filename)
pixels = image.load()
width, height = image.size
bgcolour = pixels[0,0]

morse = {
".-":"a",
"-...":"b",
"-.-.":"c",
"-..":"d",
".":"e",
"..-.":"f",
"--.":"g",
"....":"h",
"..":"i",
".---":"j",
"-.-":"k",
".-..":"l",
"--":"m",
"-.":"n",
"---":"o",
".--.":"p",
"--.-":"q",
".-.":"r",
"...":"s",
"-":"t",
"..-":"u",
"...-":"v",
".--":"w",
"-..-":"x",
"-.--":"y",
"--..":"z",
"-----":"0",
".----":"1",
"..---":"2",
"...--":"3",
"....-":"4",
".....":"5",
"-....":"6",
"--...":"7",
"---..":"8",
"----.":"9"
}

morsecode = ""


for i in range(height):
line = [0 for i in range(width) ]
#print(line)

mcode = ""

for x in range(width):
if pixels[x,i] != bgcolour:
line[x]=1
left = pixels[x-1,i]
right = pixels[x+1,i]
if left != bgcolour and right != bgcolour:
mcode += "-"
elif left == bgcolour and right == bgcolour:
mcode += "."
else:
pass

if mcode:
morsecode += morse[mcode]
#print(mcode)
#print(line)

print(morsecode, end='')


#convert image to morse code

#output ascii rep

0 comments on commit 8aa6a36

Please sign in to comment.