Breaking Aljazeera’s CAPTCHA

I was on Aljazeera Arabic’s website the other day and, as I was voting on a poll, was presented the following screen:

The CAPTCHA in the screen above immediately caught my attention. The distortions in it seemed very simple, the text was not warped in any form and no overlap between characters.

The following is a URL for one of the CAPTCHAs:

Opening the URL above and refreshing the page a few times gives the following CAPTCHAs:

The dashed grey lines are randomized, while the letters in the CAPTCHAs above are static. The letters are encoded in the Code parameter in the URL. Notice that there are two forms for each character; a straight form and another that is slightly rotated.

Aljazeera’s CAPTCHA can easily be broken by doing the following:

  1. Removing the dashed grey lines
  2. Finding the characters in the image
  3. Separating the characters in the image
  4. Classifying each character

I’ll be using Octave/Matlab for the above tasks and will be explaining my algorithm using the following CAPTCHA as an example.

Continue reading “Breaking Aljazeera’s CAPTCHA” »

Interning at TellApart

My Summer this year was unique in many ways. It was the first time I ever see the Pacific, the North American West Coast, California, and the San Francisco Bay Area. It was also the coldest Summer I ever experienced, having to wear a sweater on most nights. Apparently, this is the “normal” San Francisco Summer. More importantly though, was my Summer internship at TellApart.

TellApart is the fourth company I join for an internship and, over the course of sixteen weeks, my internship at TellApart grew to become the most rewarding and memorable internship I have experienced so far.

One of my main goals in joining TellApart was to experience the startup culture in Silicon Valley. TellApart has a very open and transparent culture; every member of the team knows about everything that goes on in the company. The team, aside from being super-talented, is always willing to listen to ideas, comments and suggestions (even from the intern!) A big portion of my internship was spent working on ideas that I proposed myself, and I started working on them within a week of proposing them!

Being a small company, it was very insightful to see the company evolve over a period of 16 weeks. Continue reading “Interning at TellApart” »

El-Tetris in HTML5. See it in action!

Following up on my previous post on the El-Tetris algorithm, a Tetris player that clears 16 million rows on average per Tetris game and, at the time of this writing, is the most performant one-piece Tetris AI out there, I thought I would provide an implementation, rather than just a description of the algorithm.

This algorithm is implemented fully in Javascript and the rendering is done in HTML5 canvas. The rendering is purely for cosmetic reasons (so you can actually see how the game is progressing). If you’re only interested in the final score, you can choose to speed up the game by enabling “Hardcore Mode”. In that mode, rendering the board will be disabled and the algorithm will run continuously in the background. You can also change the size of the board; the smaller the board, the shorter the game.

Full source code can be found here.

Note: For faster execution, use Google Chrome.

inFormed – A LinkedIn Hackday Project

Last Friday I participated in the LinkedIn Intern Hackday event that was hosted at LinkedIn’s headquarters in Mountain View. I joined my classmates from Waterloo Michael Truong, Kenneth Ho and Sumit Pasupalak.

We started a project dubbed “inFormed”. The aim of the project is to raise awareness on global issues around the world. Currently, it’s a Firefox plugin. As you browse the web, it will analyze the content of the page you are browsing and, based on that content, will show a fact, or a statistic, that is both relevant to the content of the page and related to a global issue. Along with that, it will provide a link to a charity where you can donate and/or get involved.

For example, if you are buying a book online or browsing an educational site, you would see, at the bottom right-hand corner, something like this:

Have a look at the screenshots below for some more examples. Take a close look at the fact displayed at the bottom right-hand corner and notice how it’s related to the content of the page.

[nggallery id=informed_screenshots]

To summarize, the goals behind inFormed are the following:

  • Help you stay informed on global issues around the world.
  • Facilitate how you can be involved by providing links to related charities.
  • Provide a seamless and an uninstrusive user experience.

Behind the scenes, inFormed sends the URL of your current page to the server where we fetch the content of that page, extract the text, and run it through a Naive Bayes classifier to select what is likely to be the most relevant fact or statistic on that page, and feed that back to the browser.

This event is the first hackathon we ever participate in, and we are well proud to have made it to the final round! We didn’t win the event, but were extremely impressed at the quality of the projects that people presented.

We had some votes on twitter as well:


inFormed will need a little more work to be ready to publish. Should we invest the time in doing so? Would you use it? Let us know!

From the Far East to the Far West

So the past few weeks have been quite hectic, having to relocate from the far East (Singapore) to the far West (California) along with starting my internship at TellApart.

Within a span of eight days, I surfed through six cities in five flights over four continents. Here’s the timeline:

  • May 7, 2011: Singapore, Singapore ✈ Dubai, UAE ✈ Cairo, Egypt
  • May 14, 2011: Cairo, Egypt ✈ Paris, France ✈ New York, USA
  • May 15, 2011: New York, USA ✈ San Fransisco, USA

My one week visit to Egypt marks my first visit after the January 25th revolution. Traces of the revolution are certainly visible everywhere you go – stickers on street carts saying “January 25”, spray painting on walls and bridges denouncing Mubarak and his regime and barbed wires around the Maspiro Television building. There was also a protest to express solidarity with Palestine in Tahrir square on Friday, May 13th. Hopefully political and economical improvement would be as visible in the near future.

For the first ten days in California I stayed at USA Hostels near the Civic Center in San Francisco. The commute time to work was around 75 minutes. One of the weekends the hostel was fully booked and didn’t have room to accommodate me. Thankfully, Stan Chen, my workmate, let me stay over at his place then. I have now settled in a house a few blocks away from work.

I am really enjoying my work at TellApart so far. In many ways it was exactly what I was aiming for this work term. It’s a great mixture of really smart people to work with, a startup environment, and serious scalability issues to deal with.

Aside from that, I really don’t know what else to say. In fact, I have no idea why I am writing this post right now. Off to bed.

El-Tetris – An Improvement on Pierre Dellacherie’s Algorithm

Update: Full source code and implementation now available here!

This algorithm is part of a project I was working on last term as part of my Artificial Intelligence class. This algorithm, which I will be referring to as “El-Tetris”, is an algorithm for playing Tetris by inspecting only one piece at a time (as opposed to two or three pieces in some variations of the game). It is based on Pierre Delacherie’s Tetris algorithm, which is known as one of the best one-piece Tetris playing algorithms.

Before discussing the details of the algorithm, let’s briefly look into how you, a human player, would play tetris.

When you play tetris, you are faced with two decisions every time you are given a tetris piece:

  1. Where to position the piece
  2. Which orientation of the piece to play

Naturally, you want to eliminate as many rows as possible and maximize your score. To accomplish that, you would (subconsciously) be doing the following:

while the game is not over:
  examine piece given
  find the best move possible (an orientation and a position)
  play piece

What would be the best possible move then? You would usually try to eyeball certain features to help you determine that. You might, for example, ask yourself these questions:

  • If I were to play the move, would that create holes in the game board?
  • If I were to play the move, how many rows would I clear?
  • If I were to play the move, what would be the height of the highest column?
  • … and so on

That’s exactly what El-Tetris does. For every given piece, it evaluates every possible orientation and position against a set of features. The move with the best evaluation is the one that is played.

Continue reading “El-Tetris – An Improvement on Pierre Dellacherie’s Algorithm” »

Terima Kasih Indonesia

As my exchange term here in Singapore is approaching its end, I thought it might be worth backpacking just one more time before getting sucked into the funnel of final exams. This time I went on a five day trip to Indonesia with Zhang Jing, my neighbour here in Kent Ridge Hall, and Nick Yang.

We were trying to see as much of Indonesia as possible within these five days so our schedule was really tight. Knowing how much I love bullet points, these are some of the places that we visited (in chronological order):

  • Mount Bromo, an active volcano in east Java
  • Surabaya, Indonesia’s second largest city
  • Sampoerna’s Tobacco Factory
  • Borobudur, the largest Buddhist temple in the world
  • Yogyakarta City
  • Kraton, the palace of the Yogyakarta Sultanate
  • Jakarta, Indonesia’s capital and largest city
  • University of Indonesia
  • Masjid Istiqlal, the world’s third largest mosque
  • National Museum

Other “side accomplishments”:

  • Took four flights in five days with four different budget airlines (Jetstar, Batavia, Air Asia and Tiger Airways)
  • Hiked up a mountain peak across from Mount Bromo to see the volcano at sunrise
  • Horseback rode up to the crater of Mount Bromo (lots of ash)
  • Rented motor bikes and drove around the villages in Borobudur
  • Attended a lecture on sequential circuits at the University of Indonesia (taught in Indonesian)
  • BONUS 1: Did not get pickpocketed!
  • BONUS 2: Stayed within budget!

During the trip, I only managed to learn the Indonesian word “terima kasih” meaning thank you. For all the great adventures that you offered me, terima kasih Indonesia.

Done Chinese 1!

After spending six hours every week in Chinese lectures for the past twelve weeks, today the course has – sadly – come to an end. I was fortunate to have both a lovely teacher, Ms. Lin Chiung Yao, and awesome classmates. I definitely learned a lot from both Lin Laoshi (Laoshi is Chinese for “teacher”) and from my classmates. Throughout the term we learned approximately 180 chinese characters and 150 phrases to communicate in simple daily situations. Will try to practice whenever I can!

Learning Chinese is an eye opener for me in many ways. Besides the obvious intent of learning Chinese for the purpose of communicating with Chinese people, there are some insights that I can see. Let me give you some examples:

1. Tones

Being both an Arabic and an English speaker, the concept of tones was very new, and very strange, when it was first introduced to me. It turns out that the pitch in which you pronounce a syllable determines the word that you intend to say. To see what I mean, listen to the audio clips in the table below. The four rows in this table refer to the four tones/pitches that are found in Mandarin Chinese. They are all pronouncing the same syllable, but the pitch in which it’s pronounced determines which of the four words below you mean.


Pinyin Chinese Character Meaning Sound Clip
mother [audio:|titles=First Tone]
hemp [audio:|titles=Second Tone]
horse [audio:|titles=Third Tone]
scold [audio:|titles=Fourth Tone]


Weird, huh?

2. Culture and Society

In case you didn’t know, Chinese doesn’t have an alphabet. It is, more or less, a set of characters, the majority of which are based off of pictures. Consider the Chinese character for the word “home” (pronounced “Jiā”) and how it evolved over time:

Current Chinese Character In 259 B.C. In 1046 B.C.

Looking at the origin of the character, it is a picture of a house with a pig inside. This gives an insight in what the Chinese consider to be a home (shelter, roof and live stock) at least at the time the character began to be used.

Another example is 外婆 (pronounced “wàipó”), which means grandmother on mother’s side. This word consists of two characters. The first character (“wài”) means outside, indicating that the grandmother is considered an “outsider” in the Chinese family.

In Arabic we have the saying “من تعلم لغة قوم أمن مكرهم”, which roughly translates to “He who has learned the language of people is safe from their mischief”. Looking back, I couldn’t agree more with this statement. When you learn a language you are not just learning how people communicate with each other, but also how they think.



Acting in Chinese? I think so!

As our Chinese course is nearly coming to an end, we were asked to spice things up a bit by creating our very own short film in Chinese! We had to find a native Chinese speaker and interview him with at least ten questions from the vocabulary we had learnt. Check it out!

While you’re at it, checkout the full blog and the making of below (just so you know what we’ve been through) 😀

I Want That Arabic T-Shirt

A few days ago I attended the TEDxKRP 2011 conference hosted here at the National University of Singapore. The conference was heavily geared towards social entrepreneurship and featured some really interesting talks by well respected speakers from all over the world.

Needless to say, all the talks were very beneficial and enlightening. However, there was one particular talk that caught my attention. Before I dig into that though, let me first give a brief prelude so that you would understand why I became interested in that particular talk.

If there’s one thing you should know about me, then it would probably be my obsession with the Arabic language. I immensely enjoy reading Arabic poetry and literature and I am compelled to admire Arabic’s beauty and descriptive power. The way the characters are designed and how they are conjoined leaves a lot of room for very artistic works of calligraphy.

Descriptive power and calligraphy are not the main reasons of my obsession with Arabic, however. The main reason is the strong connection binding Arabic, the language, to Arabs, the people. As fractured and divided the Arab world is today be it on the political, economical or racial level, Arabic is one of the very few common denominators that are left.

If Arabic is one of the very few denominators that portray an Arab’s identity, then why is it the case that Arabs try to run away from it? Continue reading “I Want That Arabic T-Shirt” »