Sunday, May 22, 2011

Sudoku Wizard - a Google Goggles Experiment

Google Goggles posts:
Back in February, I worked on reverse engineering the Google Goggles service and came out with some pretty good results. With more or less a working API set, I decided to write an application just to have fun with the stuff.

So you ask, "what did you exactly build?" I remember back in January when Goggles 1.3 was announced, Google demoed a nifty new feature in Goggles, which recognizes a Sudoku puzzle when provided a picture of one and solves it for you. I was really intrigued with the service since, and that's what drove me to reverse engineer the protocol. So back to the question, I wrote a Sudoku solver Windows Phone 7 application that does just that. You might also ask, "why Windows Phone 7?" Well, it's simple really. Google Goggles is available on iOS and Android platforms - it wouldn't make much sense to build another app targeting those platforms.

If you happen to have a WP7 in your possession, check out the "Sudoku Wizard" app
here. Did I mention it's free (yes, Ad-free too).

Sudoku Wizard was written using the information from my previous
post. In my previous post, I said that there are two headers that need to be added to all HTTP communication with Goggles. There is another header required for this to work. I needed to modify the user-agent as well. Apparently, Goggles requires an iOS/Android device (or perhaps a WebKit browser) in order to solve your Sudoku puzzle - and that's easily taken care of by modifying the user-agent of each HTTP request. I omitted it from my instructions in my previous post because I had thought it was insignificant. So the only thing different that I needed to do was to change the user-agent in all of the HTTP POST requests. The headers now look like:

    Content-Type: application/x-protobuffer
    Pragma: no-cache
    User-Agent: Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_1_3 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7E18 Safari/528.16 GoogleMobileApp/ GoogleGoggles-iPhone/1.0; gzip

In C#:

httpWebRequest.UserAgent = "Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_1_3 like " +
"Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7E18 " + 
"Safari/528.16 GoogleMobileApp/ GoogleGoggles-iPhone/1.0; gzip"

When posting an image of a Sudoku, Goggles will respond with a protobuffer blob with some URLs in it. Goggles solves the Sudoku and returns the solution in a URL, which needs to be displayed in a browser. An example of a response is shown below. The highlighted URL is the one that contains the solution and needs to be shown to the user (keep in mind that the URLs will be expired by the time you have viewed them):


    similar image...;..

    ....... .....1./
    Sudoku PuzzleB.J
    Sudoku PuzzleR.ZO   

    Sudoku Puzzle.
    Sudoku Puzzle...;..+.8.n._.2.965f0e6e1638152b"..


There is obviously some amount of parsing that I had to do to extract the URLs that I am interested in. I did not implement a protobuffer interpreter/parser - I just used some .NET String methods and regex to get what I need and it works great.

Sudoku Wizard.


  1. To get full source code would be good :)

  2. You seem quite proficient at programming and in exactly the areas my idea requires. I have an idea that will apply technology in a way that has never been done before and I am looking for talented programmers to innovate with me to change the world the way facebook did. Please email me so we can talk a little more, Thanks.