12 Feb 2008

7 Segment Ascii Captcha

A captcha is a security measure to test if the user is human or not. The idea is to make it easy for humans to read and tough for robots to do so.

The 7-segment display technique can be used to create a lightweight captcha. Here is a simple Javascript example to do so.

var segments = new Array (
  ' _ | ||_|',
  '     |  |', 
  ' _  _||_ ',
  ' _  _| _|', 
  '   |_|  |', 
  ' _ |_  _|',
  ' _ |_ |_|', 
  ' _   |  |', 
  ' _ |_||_|', 
  ' _ |_|  |'
);

var draw = function (n) {
  segment = segments [n];

  segment = segment.substring (0, 3) + '<br>' + 
    segment.substring (3, 6) + '<br>' + 
    segment.substring (6, 9);

  segment = segment.replace (/ /g, '&nbsp;');
  document.write ('<div style="float:left">'+segment+'</div>');
}

With some CSS adjustments, this is what the numbers would look like.

Captcha

Note that the font needs to be Monospace based for the number to be displayed correctly.