Programming 2
From Kyle's Wiki
This challenge involves taking an image that has morse code embeded in it. We have to take that image, decode the morse code quickly.
#!/bin/bash mv /root/Desktop/PNG.htm 1.png convert 1.png 1.bmp OUTPUT=`./solve.py` ./decode.sh $OUTPUT
So we need a bitmap first, we need to extract the morse using solve.py, and then use decode.sh to decode the morse.
#!/usr//bin/python import Image import sys im = Image.open("1.bmp") newnumber = 0 oldnumber = 0 counter = 0 width = range(0,100) hight = range(0,29) for each2 in hight: for each1 in width: it = im.getpixel((each1,each2)) if it == 255: newnumber = counter print chr(newnumber-oldnumber), sys.stdout.softspace = 0 oldnumber = newnumber counter = counter + 1
This code extracts the morse code. Decode.sh is a bunch of sed that converts the dots and dashes into real letters:
MORE=`echo $* | tr "." "0"` MORE="$MORE \n" echo $MORE | tr . 0 | sed -e {s/0----\ /1/g} -e {s/00---\ /2/g} -e {s/000--\ /3/g} -e {s/000-\ /4/g} -e {s/00000\ /5/g} -e {s/-0000\ /6/g} -e {s/--000\ /7/g} -e {s/---00\ /8/g} -e {s/----0\ /9/g} -e {s/-----\ /0/g} \ | sed -e {s/-0-0\ /c/g} -e {s/-000\ /b/g} -e {s/00-0\ /f/g} -e {s/0000\ /h/g} -e {s/0---\ /j/g} -e {s/0-00\ /l/g} -e {s/0--0\ /p/g} -e {s/--0-\ /q/g} -e {s/000-\ /v/g} -e {s/-00-\ /x/g} -e {s/-0--\ /y/g} -e {s/--00\ /z/g} \ | sed -e {s/0--\ /w/g} -e {s/-00\ /d/g} -e {s/--0\ /g/g} -e {s/-0-\ /k/g} -e {s/---\ /o/g} -e {s/0-0\ /r/g} -e {s/000\ /s/g} -e {s/00-\ /u/g} \ | sed -e {s/0-\ /a/g} -e {s/00\ /i/g} -e {s/--\ /m/g} -e {s/-0\ /n/g} \ | sed -e {s/0\ /e/g} -e {s/-\ /t/g} echo
A zip with all the code: File:Prog2.zip