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/0.7.3.5675 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/0.7.3.5675 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):

    2f6


    ..
    ..
    ..00407003060000810701300000503871000000000000000005932050000
    210107800006090060700|854971632629538147713246895238  
    714569965382471471659328586497213147823956392165784.
    similar image...;..

    ....... .....1./http://www.google.com/goggles/images/sudoku.png:
    Sudoku PuzzleB.J
    Sudoku PuzzleR.ZOhttp://www.google.com/goggles/result?cssid=   
    30F2B33236EF604A&rh=061F6991C6883113...;Q.Ohttp://  
    www.google.com/goggles/result?
    cssid=30F2B33236EF604A&rh=E3378E086956A162...=.

    Sudoku Puzzle.
    Sudoku Puzzle...;..+.8.n._.2.965f0e6e1638152b"..
    +TR=T=47zjUtTuOC0:X=N2eE6:S=_Wfmn5yVnPqmIncl
    +TR=T=VRi6Lyke0hg:X=N2eE6:S=v6Pd5Kfnqtmr6F1u
    +TR=T=1Ez8_2tSjsc:X=N2eE6:S=ZH8A8bLT2fSEU0L0
    +TR=T=itRprQ9o70M:X=N2eE6:S=H8Oyx0Srj8HaeyQL
    +TR=T=A4_uRb4_Axg:X=N2eE6:S=_afui5_H60kiNDEg....

    0

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.

2 comments:

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

    ReplyDelete
  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.

    -Liam
    savagewings@gmail.com

    ReplyDelete