This week's excercise
by phil | Nov 16, 2011 - 11 a.m.
Yesterday, I realized that I hadn’t started thinking about what my writing exercise would be this week. I usually have some ideas by Tuesday, but this week was coming up dry. I spent some time considering various short fiction options, although I’m not sure that that’s what I want this blog to be about, or if this is even a good medium for that. So really, nothing.
Then, this morning, I realized that I was doing my weekly writing out of the blue. I was writing a letter to my congressperson, and it was, as a bonus, good practice. Congress is currently considering a bill called SOPA (Stop Online Piracy Act), which has potential to undermine the way we use the internet. While the legality and morality of piracy is debatable, this bill would put in place measures that are a threat to online free speech and innovation, two things we can ill afford to lose. You should
read about it and decide how you feel.
If you decide that this bill will be a bad thing, you’ll be in the company of Google, Yahoo, and a number of other prominent internet companies, and I would urge you to also
write your congressperson. I’m of the opinion that if you like
the internet as it is now, you should be opposed to this legislation.
Sorry to be a bit preachy, but as someone who makes their living working online, this sort of thing threatens me personally as well as having terrible ramifications for status as a free society.
0 comments
Regarding books and ciphers
by phil | Nov 7, 2011 - 08 p.m.
I’ve been trying to write about something (anything really) at least once a week. Last week I failed at this for a variety of reasons, and the week before I wrote a draft of a recipe post for my (and my girlfriend’s) other blog,
Usversusdinner.com, which is about our cooking adventures. I’ll post that once I get it edited and put some pictures into it. This week, I’m getting right back on the horse with this post.
I’m a big fan of
Penny Arcade, and about a month ago, the
news post was written by a game developer who also happened to be an expert in cryptography. In the post, she included two blocks of numbers: “28-1 10-2 10-3 6-4 18-4 43-1 36-3 9-2 43-4 32-9 41-2 1-1 2-1 45-1 42-3 33-2 3-4” and “42-4 14-2 26-1 32-10 35-3 54-3 56-1 3-3”.
I was curious about these, so I did a bit of poking around and discovered that they were the cipher text produced by a type of
Book Cipher. You, much like myself before this exercise, may not be familiar with a book cipher. Simply put, a book cipher relies on an existing piece of text, usually a book (go figure), as a key for decoding a message. The coding of the message often isn’t complex - usually numbers refer to words in the key text. The obscurity of the cipher comes more from knowing what the key text is, less from the complexity of the code.
Every news post on Penny Arcade accompanies a given comic, so it isn’t terribly difficult to guess what the key text for this particular cipher text is (it is
this comic).
In this instance, the way the message is coded is “word number-word letter”. I was curious what the message was, so I started to counting through the words and then counting through the letters. As it turns out, this is an incredibly dull, slow, and completely unrewarding process. In the past, this was no doubt was a “security feature” of this type of cipher.
Fortunately for me, we live in a world filled with computers, and computers are great at this type of thing. I whipped up a little program in python that de-crypted the text in almost no time. The longest part of the coding session may have been transcribing the text of the comic.
base_cipher = "28-1 10-2 10-3 6-4 18-4 43-1 36-3 9-2 43-4 32-9 41-2 1-1 2-1 45-1 42-3 33-2 3-4 42-4 14-2 26-1 32-10 35-3 54-3 56-1 3-3"
key_text = "Sir I need you to turn off your my what you want me to turn off my book oh you'd like that I bet you'd love to turn off all books wouldn'tcha yeah just \
like hitler uh oh too far you're gonna shock my genitals huh the genital region I think we might start there yeah"
code = base_cipher.split(' ')
key = key_text.split(' ')
for i in code:
parts = i.split('-')
index = int(parts[0]) - 1
print key[index][int(parts[1]) - 1]
It’s quite simple thanks to the way that python keys strings just like arrays. I’ve considered trying to re-write it as a one liner, but it didn’t seem like a good use of time.
Here’s the short explanation. I split both the cipher text and the key up by spaces, and then cycle through each word-letter pair of the cipher. I split those by the dash, and then use the word part of the pair to grab the right word, and the letter part of the pair to grab the write letter from that word. There is also the subtract by one to compensate for the cipher using an index that starts with one and python using an index that starts with zero. Easy stuff.
You can grab the code if you like from
my bitbucket account. I won’t say what the message is, but it actually isn’t very interesting. No worry though, as I had a great time finding it. I’ve found that with most worthwhile pursuits, the fun isn’t in the destination as much as it is in the journey. Enjoy!
0 comments
Who are you online?
by phil | Oct 18, 2011 - 07 p.m.
I was reading
an article discussing some comments made my moot - the guy who created 4chan and canv.as. He has some pretty strong feelings about anonymity and how it effects the way we interact with each other online. I think there is definitely a place for both identities in the online world. On this page, I'm obviously not too shy about my identity, but on other sites I take on a more pseudo-anonymous identity (reddit for example), as I think most people do.
The article got me thinking about how closely our online personas reflect our actual personalities. Are you as willing to speak out when going by your real name as you are when going under a pseudonym? I think I'm a bit more careful when using my real name, but for me, my pseudonym also has a bit of a reputation to maintain. To me, my pseudonym is a separate part of my identity, but still definitely "me". As a general rule, I try not to be a dick regardless of how personally liable I am for my statements, but I can see how it can be appealing to let loose completely in online form. When you are anonymous, there is almost no chance of suffering interpersonal consequences for your actions.
The article also reminded me of a conversation I had with my girlfriend a few days ago. She is still friends on facebook with an RA that she had our freshman year of college. He now lives in the midwest and is married to a girl he met through an online forum. The story goes that they were friends online, dated online for several years, and when college was over, he moved out there and married her. They had only met in person one time before they moved in together. I imagine that to many people, this sounds insane. How could you get along with someone that you had only met "for real" one time? It doesn't make a whole lot of sense. But what if you had put enough of yourself online that your interactions there were “for real”? I don't think that I've ever made a friend online, but I also don't think of my online self as my whole self. If you truly present your whole self, as I imagine the guy in our story does, then he wasn’t moving in with someone he barely knew, he was moving in with someone he’d known (and dated) for years. It still seems a bit strange to me, but as we spend more time online and as younger people grow up not knowing a world without an online component, I think it will become more and more common.
0 comments
A little (more) command line fun
by phil | Oct 6, 2011 - 08 p.m.
I've written about this before, but at the risk of contradicting myself in the future, I'm going to say I don't think I'll ever get tired of coming up with command line solutions to little problems. The beauty of unix is the way that you can stitch together programs to make your life easier.
It might be one of those things that I like because it makes me feel clever, but if that is case, so be it.
The problem I was trying to solve was simple. I needed the current version of an svn repository so I could insert it into another file during a build process. Since we're running the script inside an versioned directory, the command "svn info" will give us this.
[pwade@web48 philwadeorg]$ svn info
Path: .
URL: http://example.com/phil/trunk/philwadeorg
Repository Root: http://example.com/phil
Repository UUID: 6596c492-bec3-4f50-a8a2-b0ff2d2738bf
Revision: 445
Node Kind: directory
Schedule: normal
Last Changed Author: phil
Last Changed Rev: 384
Last Changed Date: 2010-12-14 09:37:56 -0600 (Tue, 14 Dec 2010)
Neat! We've got our revision right there: "Revision: 445". Too bad it's surrounded by a bunch of crap that we don't want. Grep lends a hand here.
[pwade@web48 philwadeorg]$ svn info | grep Revision
Revision: 445
Much closer now, but we want just the number, nothing else. The next tool we're going to grab is awk. If you're not using sed and awk, you really should be. Unix is all about moving around text, and sed and awk are all about manipulating that text, which, as you might imagine, comes in handy. My dad passed down the O'reilly
Sed & Awk book when I started working, and it's been very useful. It sits on my shelf, and when I need to figure out something like this, I pull it down and make stuff happen.
Anyway. Awk. At the most basic level, awk just takes a line of input, and splits it into separate pieces, delimited by spaces. These are referred to like so: $1, $2, etc. For each line of input, awk will act upon those pieces how you want. In my case, all I want it to do is grab the second part of the line (the revision number) and print it out. Here we go.
[pwade@web48 philwadeorg]$ svn info | grep Revision | awk '{print $2}'
445
And there you have it. Our revision number from that big mess in just two simple steps. I was going to run this command from inside a python script, but it was actually easier to pass in the output as a argument to the script. Funny thing, that python command line library.
It should be noted you could probably solve this problem with just awk alone, or that there may be a way to get it out of just the svn command. I couldn't find an svn solution in my (admittedly short) search for one, and I think a pure awk solution would take a lot longer to cobble together.
0 comments
bitbucket! etc!
by phil | Jun 11, 2011 - 12 p.m.
So I've phased back into doing some code writing in my spare time. I tend to go back and forth between really loving to write new code and just wanting to play Minecraft/veg out all the time. I like to think of the two activities as a rest from each other.
The last round of big coding resulted in
Interflix, which I'm quite proud of, even though it isn't completely finished. I'm not sure that I will get around to finishing it, what with the official Netflix android app being released, so perhaps I'll just release the source.
Anyway, my current burst of activity involves
tgrep, a challenge I saw on reddit and initially implemented in Python. Now I'm trying to re-implement it in C, which is a quite fun. I've been working in programming languages with "C style" syntax for most of my programming career, but never bothered to learn C. I thought this was a good opportunity to do so. It is a bit more challenging than I thought it would be.
Anyways, you can now follow along with my code adventures via my
bitbucket account. Right now it's just tgrep and some
project euler code, but I'll be putting anything non-proprietary that I do up there from now on.
0 comments