Shaftoe - A Simple Web Service for Encrypting Messages Using PGP

&& [ code, featured ] && 0 comments

Wouldn’t it be awesome if we starting seeing websites like this?

signup

I usually hear people say they don’t use PGP because nobody else does. A fair complaint - PGP isn’t exactly easy to set up and without the proper motivation it’s hard to convince the people you communicate with to use it too.

But PGP isn’t so hard to set up that our machines can’t use it to send us messages. If someone wants their email send to them encrypted, it really should be as easy to tell the app in question to use their public key either by providing it or looking it up via PKI.

Shaftoe is a proof of concept of how that can be done. It’s a simple webservice, 2 methods only: one for storing keys, and the other for encrypting text using those keys. The bare minimum needed for encrypting email with PGP. You can find instructions on how to download and run it yourself on Github.

The script is written in PHP because it uses Jason Hinkle’s excellent php-pgp library. This was the only decent and working OpenPGP implementation I could find that doesn’t require a compiled binary and all it does is encrypt. In fact it works very well.

Below is an example using the service. It asks you for an idetifier and your public key in ASCII format, then returns a random encrypted quote.

The service could just as easily be used by an application to encrypt email before sending it.

View outside of Iframe

Details and installation instructions can be found on Github

The Code Book Companion

&& [ code, featured ] && 0 comments

I’ve been on a cryptology kick recently, which is really no surprise. With all the recent news about domestic surveillance and services providing private communication being forcefully shut down, I have to admit my sympathy for the foil hats has increased considerably.

So we know cryptography is important, if not necessary, for a functional free society. But it’s also really ‘effin cool.  The world of cryptography is an even mix of mathematics, information science, and civil disobedience. What’s not to love?

Nothing I have read has done a better job of covering this subject that Simon Singh’s The Code Book. Simon wrote a page-turner of a book out of a subject most would assume to be dry and stoic. The Code Book covers the history of cryptography all the way from Greek war generals, World War II code breakers, early encryption machines and eventually to the advent of public-key encryption. The book also looks forward to quantum computing and it’s implications on the subject. Although published in 1999, the book remains extremely relevant. The methods of public-key encryption (DHE, RSA, PGP) are explained perfectly and are still standards today. The only time the book shows it’s age is the lack of a mention of Elliptic Curve Cryptography which was proposed in 1985 but is just now gaining popularity as an alternative approach to public-key cryptography.

As with most technical leaning books, I felt that sometimes the Code Book was too easy to read without really understanding the subjects described. Indeed, Simon does such a good job of portraying the human aspect of cryptography that often I just wanted to know what would happen next to whichever mathematician/social dissident/treasure hunter was currently the subject. So I decided to slow myself down.

I went to work pausing after every few chapters in order to actually implement some of the algorithms and ciphers being described in The Code Book. The result is this small website where I placed them for anyone who is interested. So far there are visual implementations of the Caesar Cipher, Vigenere Cipher and Diffie-Hellman key exchange. There is also a tool to perform frequency analysis on two texts and compare the results.

Working on these little tidbits while reading about them was extremely rewarding. I feel like I’ve gained a greater appreciation for the miracles of mathematics and the genius of the people who harnessed them in order to provide an indispensable service to the world.

I’ve finished the book now, but I plan on writing more implementations. Possibly RSA? A version of Diffie-Hellman using elliptic curve cryptography? We’ll see.

www.toxiccode.com/codebook

The code for the page is available on Github.

Oven Training

&& [ Cycling ] && 0 comments

103degrees

Graphing the Tour De France

&& [ Cycling, Code ] && 0 comments

Two things are going on right now:

  1. The Tour De France.

  2. I need to learn a new charting library.

I started looking around and Highcharts seemed like a nice JS solution with a complete API. It does require a license for commercial use, though.

At the same time, I found a bunch of cool historical data on the Tour De France. I set up a MySQL database, made a few PHP pages, and here we have the results.

The most interesting metric is the average speed of the winner over the years. It is amazing to see the acceleration, though there appears to be an plateau or possible even a decline in the last few years. Doping possibly?

What ages are winning the tour?

And the obligatory wins by country:

Now, back to watching the races.

Snake Road is Awesome. Soon it Won't Be.

&& [ Art, Cycling ] && 2 comments

Snake Road follows the Carquinez Strait connecting Port Costa and Martinez, CA. During the Loma Prieta in 1989 a large portion of the road fell in to the strait and it was never repaired. As a result the road is closed to vehicles and is in a state of glorious disrepair.

What better to do with a large swath of pavement unreachable by law enforcement? Paint it! And that’s exactly what people do. There is hardly a square foot to be found that is not covered in some sort of painting or splash of color.

I’ve had some pretty cool commute routes in the last few years but this section of rutted, eroding, road-as-art-gallery has been by far the best. Alas, not all is well on the windy, winding road. The Easy Bay Regional Park district has in all their wisdom, deemed this road “unsafe.” Snake’s fate? To be paved over as a pedestrian/bike path. It is absolutely heartbreaking.

I’m not sure when construction will begin in earnest and I will no longer be able to ride this route. I decided that I better take some pictures while I have the chance. I also uploaded a video (sorry for the shakiness) that sort of illustrates how awesome it is to ride on this road. Contact me if you’d like the full size images. They were taken with a cell phone, so not that great.

{% flickr_set 72157635968611896 %}

Coding Restore The Fourth

&& [ code, featured ] && 0 comments

Recently we have learned that a certain branch of the government may be overstepping the consitutional right to privacy. While this may be old news for many the recent leaks by Edward Snowden have brought the issue to national attention and have caused quite a stir.

And rightly so, the argument can be made that the NSA is violating the forth amendment. Restore the Fourth, a grassroots organization that sprung up nearly overnight, is making that argument and taking it to the public.

From the website:

Restore the Fourth is a grassroots, non-partisan movement; we believe the government of the United States must respect the right to privacy of all its citizens as the Fourth Amendment clearly states. We seek to bring awareness to the abuses against our civil liberties and the erosion of this cornerstone of our democracy.

I’m sympathetic with this cause. And despite most likely being placed on a government watch list for the rest of my life, I decided to take a crack at building these folks a website. The decision was made to use Django, a neat framework written in Python.

One of the most interesting features of the website is the map on the front page. The locations are set by pulling objects from the database that represent protests. These objects are editable in the back end by regular admins using Django’s awesome gui admin interface so developers do not need to be involved.

When creating a protest via the admin interface you don’t need to supply a latitude/longitude pair (which are needed for google maps) but instead the backend utilizes the Google Maps Geolocation Api so all that’s needed is a city and/or state. To make that process easy, we’re using geopy, a geolocation library for Python. In the Protest model, we can simply call this:

{{< highlight python >}} def generateLatLong(self): g = geocoders.GoogleV3() place, (lat, lng) = g.geocode(“{0} {1}”.format(self.state, self.city),exactly_one=True) self.latitude = lat self.longitude = lng {{< / highlight >}} to generate a proper latitude/longitude pair for the object, using it’s city and state.

Then in our views, we make a method to serialize these objects as json: {{< highlight python >}} def protestsjson(request): protest_list = Protest.objects.all() data = serializers.serialize(‘json’, protest_list) return HttpResponse(data, mimetype=”application/json”) {{< / highlight >}}

From there, its just a matter of telling the google map to use those objects to create markers:

{{< highlight javascript >}} var map = new EventsMap(); $.getJSON(‘/protests.json’, function(data){ map.plotStaticMarkers(data); });

// plot new markers on the map, make them interactive this.plotStaticMarkers = function(data){ $.each(data, function (i, location) { var latlng = new google.maps.LatLng(location.fields.latitude, location.fields.longitude); var marker = new google.maps.Marker({ map: map, position: latlng, title: location.fields.city });

     google.maps.event.addListener(marker, 'click', function () {
     var content = infoWindowTemplate
          .replace('{location}', location.fields.city)
          .replace('{info}', location.pk);

     infoWindow.setContent(content);
     infoWindow.open(map, marker);
     });
})

} {{< / highlight >}}

And there we have it, a neat interactive map that doesn’t require a developer’s involvement to edit.

Check it out in action: restorethefourth.net

As usual, the source is available on Github

How Gnar? Cycling App for Android

&& [ Cycling, Code ] && 0 comments

I recently began to foray into programming for Android. Being already experienced with Java and the general ecosystem of Java enterprise development, I feel right at home.

My first creation is called How Gnar? and the premise is simple: start the app at the beginning of your ride and receive a “gnarness” rating at the end of your ride with accompanying images and audio.

It’s kinda like Strava, but really useless and dumb.

Anyways, if you want to check it out, download it here: http://toxiccode.com/misc/HowGnar-debug-unaligned.apk

All the source is available on Github: https://github.com/AustinRiba/howgnar

Enjoy.

screenshot

 

The Fountainhead

&& [ Books ] && 0 comments

fountainhead

I just finished reading Ayn Rand’s beast of a novel, The Fountainhead. I enjoyed every one of this book’s ~800 pages and myriad of characters. Though I found some of the ideas  put forward in the novel hard to agree with, and others downright baffling, Rand’s talent as a writer makes this book intoxicating.

Taken at face value, The Fountainhead is an impressive novel about a revolutionary (this word is never used in the book, can anyone guess why?) architect named Howard Roark who refuses to compromise his ideals under any circumstances. He is a champion for modern architecture in a society that is stuck on classicism. Architecture serves as the background of the novel however I felt that Rand’s descriptions of buildings and the architectural process alone made the book worth reading. Since I started the novel (a while ago, this is a long book), every time I walk down a street in San Francisco, my head eyes are always turned up. I don’t know why I never appreciated buildings as works of art with their own soul and grace given to them by an architect, but I do see them in a completely different light now.

The architecture makes this book good but it is the characters that make it great . The names Roark, Francon, Toohey and Wynand will likely never be forgotten by me. The amount of depth given to each character made them feel more real than in any other book I can remember reading. I felt heroic when reading Roark, pain and beauty when reading Dominique, powerful when reading Wynand and evil when reading Toohey. The monologues are great and the dialogue is even better. Although the characters are mostly unrealistic, it is enjoyable to fantasize about a world where such elegant and intelligent people could exist. I miss them already.

Now for the meat of the book - Ayn Ran’s Objectivist philosophy. Roark, the hero of the novel, is supposed to be the perfect man that fits in to the ideals of Objectivism. He is an extreme egoist in the sense that the world and it’s people do not concern him, only his sense of self and the integrity of his work matter.  He is a man who takes what is available to him and creates things, but it is the act of creation that is important, not any kind of worldly rewards. He doesn’t borrow from anyone else and he doesn’t give to anyone either. Roark feels enlightened because no matter what happens to him he will always have the integrity of his soul which nobody can ever take away. This is the heart of the meaning to me: our sense of self and our own objective reality are the only things we truly own, and as long as we are content with them, we are content with life.

Rand also says that it is the people like Roark that create all the great things in the world, and the “second handers” are people who never create anything of their own, that live for other people, and that are parasites of creators like Roark.

It is hard not to admire this view of integrity. I honestly think I’m a better person for having read it. The philosophy breeds self confidence and self respect. I think it will be easier for me to stand up for myself in arguments when I know that I am right, and to do what is in my best interest instead of worrying about what other people think. There is a powerful dialogue at the end of one of the chapters in which Toohey, the villain who is trying to destroy Roark’s career and legacy, confronts him:

“Mr. Roark, we’re alone here. Why don’t you tell me what you think of me? In any words you wish. No one will hear us.” “But I don’t think of you.”

I think that pretty much sums up the egoist.

… and then things start to get weird.

One of the strangest parts of the book is the rape of Dominique Francon by Roark. There is definitely a sexual undertone to the entire novel and it seems to climax in a scene where Roark forces himself on Dominique, yet you can tell Ayn is enjoying writing it. So does the character Dominique. Afterwards she is described as not wanting to bathe as to “keep him on her skin” and as walking the streets wanting to tell everyone that she had been raped, but somehow glad about it. What the hell? The whole thing is just another metaphor for Roark the creator taking what is available to him and acting in his own self interest.  But another person as the material for the creation? It’s absurd. Objectivism prides personal freedom and the rights of the self. But what good is it to take away someone else’s freedom? Now it is saying that it is not simply individualism that matters most but some form of survival of the fittest.

Another part of the philosophy that is downright vile is the view on nature. To Rand, nature is simply a resource to be consumed by man without regard to anything else. The scene directly preceeding Dominique’s rape is that of Roark as a drill man in a quarry (raping nature) and this theme repeats several times in the novel. What seems like a big disconnect to me is the idea that the “creators” creations are not bound by any limitations. It is true that it is the genius of a person that brings the creation from the mind to life but it is hard to create something out of nothing. If all the granite in all the quarries was to be used up, what would Roark build out of? Many would say he could find something else, but the earth is a finite resource. There is a limit.

Besides the handful of problems I have with Objectivism, I’ll probably continue to wonder “how can I be more like Roark” when thinking of my work. Speaking of my work, Roark would have made an excellent software engineer. In fact, he probably would have preferred it to architecture, considering you don’t need clients to build something cool.

With that said, I’m off to write some code.

And I’m very happy to write it.

What do You Think About in the Shower?

&& [ Bizzare, Science ] && 0 comments

6-sad-cat-takes-a-shower

I was sprawled on the floor today, feeling good about my sore legs from the race yesterday, about the fact that I get to stay in Fairfax for a week,  and about the interesting show that was available via Hulu on the Xbox - Nova Science Now. In this program they featured a scientist who discovered the protein called PKMzeta that facilitates electrical communication between the neurons in the brain responsible for long term memory. He also developed an inhibitor, ZIP, which could block those communications and erase memory. Fascinating stuff.

In one scene the professor describes his experience going to a sensory deprivation tank, which are small, light-less enclosures that cut off all sound and feeling and are supposed to let your mind run free. He claimed that the tank helped him come up with some profound ideas. Later in the show, he explained how he takes long showers because in they also help him think.

Thinking man comes up with his best ideas in the shower! How cliche, right?

Ironically, I was thinking about this tonight, in the shower. And then I started to wonder, why is it some common that people come up with grand ideas while in the shower? And then I thought back to Mr. Fenton’s experience with the isolation tank. Showers are like isolation chambers - but without the fancy name. The noise of the water is constant and overpowers most other noise, the water is warm and hypnotizing and you are usually in a small space with nothing much to look at. So it’s no wonder that people come up with the best ideas in the shower. There is nothing else for your  mind to do.

Happy bathing.

Putting my Dreams Down on Paper

&& [ Bizzare ] && 0 comments

Dali-sleep

About a month ago, I started keeping a dream diary. Every morning I wake up and attempt to write down that night’s dream. So far it’s been both extremely difficult and eye opening (no pun intended). I’ll tell you what kind of dreams I have, but first lets explore some of my experiences with the actual act of recording dreams.

The first thing I noticed was how quickly you forget the details of your dream. I think it’s common knowledge that most dreams vanish quickly after waking, but I’ve found that details of a dream that I feel I have locked in my head can disappear literally faster than I can write them down immediately after waking up.  I think I’m getting better at remember details though, as my entries have slowly been getting longer and longer.

Weird stuff happens when you record your dreams. One of the strangest phenomena are the dreams about writing down my dreams. Several times I have had dreams that I am recording a previous dream and then wake up in the morning confused as to why my journal did not yet have that night’s entry. Sometimes I just wake up to write down a dream because I am consciously thinking that I have to record it.

Those phenomena are actually quite encouraging because they feel like the first steps toward lucid dreaming. One of the reasons I decided to start writing a dream journal was because I read that they can help a person have lucid dreams, which I have experienced before. About 6 years ago, there was a time period of 4-5 days where I had full lucid dreams every night. Then as suddenly as the ability appeared I stopped being able to have them. I’ve been wanting to experience them again ever since.

I’m not going to claim to have any deeper understanding of my subconsciousness than when I started recording dreams, but it’s a possibility I can see having if I keep it up. When I  read back on the last month I am able to discern a few repeating patterns, but nothing earth shattering yet. Most of what I see (or understand) is pure madness. This could be attributed to the fact that some dreams that make perfect sense are absolutely impossible to put into words. I think this is because dreams are just as much about feelings and, dare I say, it, even deeper subconscious thought (queue the Inception soundtrack) then they are just experiences playing out in front of your eyes. Also, my hand writing is damn bad first thing in the morning.

Some of my nightmares are so terrible that they are hard to write down. When I started recording there were some dreams in which I intentionally skipped details simply because they were so disturbing putting them down in to words was frightening. I think it was the idea of making the dream real - putting them into words and immortalizing something I could easily (and like to) forget. I’ve since gotten over that, it felt like cheating. I want the whole picture even if some of it is ugly.

Other dreams are a joy to write down because they feel like memories I would like to keep. I go through adventures, achievements and a lot of times, just hanging out with buddies.

Nobody can ever read my dream diary. There is some deeply personal stuff in there I don’t feel anyone else should read, or could even understand. So I won’t be publishing any of the actual text from the journal, for now at least.

Although I just started, it’s been an interesting experience. I’m looking forward to more insights and possibly some of that lucid dreaming in the future.