Tag Archive for 'linux'

XKCD’s Collatz Conjecture

In the XKCD comic dated 3/4/2010, the Collatz Conjecture presents the following scenario:

Well I don’t know if your friends will stop calling your or not, but I was curious about what the graph would actually look like. The graph in the comic looks like it was created with Graphviz, one of my favorite programs!

So I wrote a quick bash script to generate the approrpiate links for graphviz to interpret:

#!/bin/bash
echo "digraph \"xkcd\" {"
for NUMBER in `seq 1 100`
do
 if [ $[$NUMBER % 2] -eq 0 ]; then #We are even
 let OUTPUT=$NUMBER/2
 else  #Odd
 let OUTPUT=$NUMBER*3+1
 fi
 echo "$NUMBER -> $OUTPUT"
done
echo "}"

So what does it really look like? Here:

There are lots of straggling links. This is of course only because I went to 100. Why not 1000? It is a little big… click Here.

Turns out with even more numbers we end up with even more isolated links, no big super chain.

If you would like to run this code for yourself, first make sure you have the graphviz package installed in your linux system. Then copy that code above into a script, say called xkcd.sh. Then run like so:

./xkcd.sh | neato -Tpng | display

Adjust as necessary.

Automated Aftershock Playing Bot

This is a bot I wrote to play Aftershock games for me. Aftershock produces these 5 games that are all basically the same, but with different themes:

Engines of War – 138071613
Undead Live – 175496321
Mark of Mafia – 833613775
Gunshock Racing – 124286853
Dragon Masters – 304299067

If you play any of these games, feel free to ally with me :) If aftershock bans me, no big deal :)

These are the types of games that make you log in often to check your status, and use your energy (otherwise it is wasted). The thing is, most of the decisions and things I do in these games are just to preocupy your time, I could write a program to do the simple things for me. So I did! Now only if I could run it periodically from a cronjob. You see, they require you to type in a CAPTCHA every time you log into the web interface, so for my program to work I have to manually log in first. But wait, the ipod app doesn’t require a captcha… if only I could run the app from the ipod, steal it’s auth cookie, then run my program it could be compeltely automated! Well the best way I could find to do this was to use the T-Plan vnc robot to do the required key presses, then let ssh and bash do the rest.

I also looked into using the Erica Utilities to start the game without the complexity of vnc, but I found they didn’t work on my platform with the 3.0 firmware. So now I can just sit back and let my robot level me up forever!

Here are some more technical details on the script itself if you are interested. Anyone who plays these games would find these features very desireable:

  • Recovers from raids
  • Repairs your buildings
  • Accepts all incoming ally invitations
  • Automatically uses all your fighting power to get at least 2exp for every fight, and choosing opponents that you can win against. (It automatically heals you if you need it)
  • Redeems combo/key/spell codes from a large number of websites to gain a huge amount of free, non-upkeep items. (And it posts your code everywhere when you have a new one)
  • Sends ally invitations to a huge list of available codes from a large number of code sharing sites to build up your command.
  • Goes through internal game pages to scrape profiles for ally codes to send more invites to.
  • Quits automatically when you reach the 50 invite 24 hour limit or if your cookie expires.
  • Deposits money in the bank

Of course you can change the order or the functions, and they are all optional. All the code is here. The code is just bash, using grep, sed, awk, html2text, cat, etc. You will want to edit the variables to meet your needs before you use it of course. You can check out the code with svn:

svn co http://dev.xkyle.com/aftershock

Explaination of commands:

aftershock.sh – Main script, takes the argument 1-5 for the particular game you are playing. Needs the -i argument if you need the cookie from the ipod instead of firefox
go-ipod.sh – Runs each game consecutivly by vnc’ing to the ipod, running the game, getting the cookie, then running the appropriate aftershock.sh instance
spawnall.sh – Runs an exterm for each aftershock game. Useful if you have logged into each game through firefox, and need the robot to just do everything

I will try to support people who genuily who want to run this program. It is GPL. Email kyle@xkyle.com if you need help.

Final Clock Post

I’ve finally moved to Colorado, and I had to leave the big clock behind, and luckily I had finished it:

photo

I finilized the code, installed the clock in my church, and programmed it for there needs. The code is stored here if someone want to see it. If you want to check it out run:

svn co http://dev.xkyle.com/clock

I have a little more technical info on my wiki, but it basically goes like this:

68fbb4a6882a094ecd708c15fca783ee

So using this and Openvpn, I can control the clock through the serial interface anywhere in the world, even Colorado! And of course the best part of it all, the church staff can also control it by sending an @reply using twitter!

Decrypting an eBook to make it Searchable

So I spent $22 on an ebook for school.

It has this crappy DRM that only lets me view the pdf on one computer using only “Adobe Digital Editions”.

If that wasn’t so bad, only a small subset of the text is OCR’d, so most of it isn’t even searchable!

Now I’m pissed, but wait, what do you say? These files are just RSA encrypted, and I have the key?

Some cool guy named i♥cabbages has released code do extract your key, and then decrypt the file to a good ol’ plain pdf. If you want to reproduce my steps you will need to use the PDF decrypter unless you have epubs.

So I use the tool and get a pdf, now I can use one of the most awesome tools in the world: Imagemagick.

Imagemagick can whip this pdf into shape. The first thing I’m going to do is convert each page into a tiff:

$ convert -density 200 input.pdf[1-124] -depth 8 -monochrome %05d.tif

Then I’m going to run tesseract-ocr on them to get the text:

$ for i in $(seq –format=%005.f 1 324)
do
tesseract $i.tif tesseract-$i -l eng
done

Now all I have to do is cat all the text together:

cat *.txt > output.txt

Now I have a fully searchable, plain text file. Exactly what I wanted in the first place!

For the REAL magic, I use agrep to search for strings similar to provided example test questions to help “highlight” the answers. More technical details on that magic on my wiki.

answer


My Wireless Cracking Tool

I’ve become a semi-expert on wireless networking and their security features.. and how to get around them. Before I continue I want to emphasize:

The act of cracking encryption is not illegal just like picking a lock is not illegal. It is the unauthorized access of that network which is illegal, just like breaking and entering is illegal.

So. To sum it up, there are two types of encryption. There is the weak kind (wep) and the strong kind (wpa). WEP can be broken in about 5-10 minutes. WPA can be broken in about 24 hours (as long as their password is in your password try-out list).

The actual process or hacking into a network like this requires a suite of tools called the aircrack-ng suite. You can read their tutorials and such, and I highly recommend you do if you want to get into this sort of thing. It’s a lot of FUN! Be prepared to learn linux while you are at it….

But, once you understand what you are doing, you will appreciate the tool I have written. It automates the process of getting the keys. I wrote it as a type of “set-it-and-forget-it” tool that I could just leave running. It isn’t too clean, but if you can read bash scripting you can figure it out.

Here is a screen shot of my tool cracking wep

Here is a screen shot of my tool cracking wep

Remember! Don’t try to just run this tool without understanding what it does and how to read it. If you haven’t breaking a wep key manually you don’t want to run this. It does WEP and WPA cracking (saving the handshake for later). Good luck! I will provide minimal support via comments on this post. Don’t forget to have your radio in monitor mode first, and if you are  going to do wpa you need the mdk3 tool.

Here is the download link to Kyle’s Wireless Cracking Tool.

Here is a link to a more updated versio of my Cracking Tool.