Learning time : CAPTCHA

We’re going to learn how how CAPTCHA (Completely Automated Public Turing test to tell Computers and Humans Apart) works and how it minimizes automatic sign-up of forms. We will also be creating a simple CAPTCHA script in PHP to illustrate this.

Basically CAPTCHA works in the following manner:
  1. Create Random Value: Some random string is generated, random values are often hard to guess and predict.
  2. Generate an Image: Images are used as these are generally a lot harder to read for computers while being nice and readable to humans. This is also the most important step as simple text in images can be read (and CAPTCHA cracked) quite easily. To make it difficult for them, developers employ different techniques so that the text in the image becomes hard to read for computers. Some create zig-zag lines for background while others twist-and-turn individual characters in the image. Possibilities are many and new techniques are being developed all the time as crackers are always into finding ways to break them.
  3. Store it: The random string generated (which is also in the image) is stored for matching the user input. The easiest way to do so is to use the Session variables.
  4. Matching: After the above step, the CAPTCHA image is generated and shown on some form which we want to protect from being abused. The users fills in the form along with the CAPTCHA text and submits it. Now we have the following:
    • All submitted form data.
    • CAPTCHA string (from form), input by user.
    • CAPTCHA string (real one, generated by us), from session variable. Session variable is generally used as it can keep stored values across page requests. Here, we needed to preserve stored values from one page (form page) to another (action page-that receives form data).
  5. If both match, it’s okay otherwise not, in that case we can give the user a message that the CAPTCHA they had entered was wrong and their form could not be submitted. You could also ask them to verify it again.

CAPTCHA Generation and Matching

From the above image it’s quite clear that when someone requests the form page, the CAPTCHA text is generated and sent back to requesting user, but only in the form of an image. If the requester is a human he’d not have much difficulty reading the image and inputting the text when asked but if it’s a bot it might face difficulties guessing whats in the image. In the next step when we match the string generated and the one the user had input, we can restrict automated form submissions.

The following is the code that does this, it’ll just output the CAPTCHA image to the browser when the script is requested:

/********************************************************
* File:        captcha.php                             *
* Author:      Snehal Masne                            *
* Date:        12-Mar-2009                             *
* Description: This file can be embedded as image      *
*              to show CAPTCHA/                        *
********************************************************/

// The number of characters you
// want your CAPTCHA text to have
define('CAPTCHA_STRENGTH', 5);

/****************************
*        INITIALISE        *
****************************/
// Tell PHP we're going to use
// Session vars
session_start();

// Md5 to generate the random string
$random_str = md5(microtime());

// Trim required number of characters
$captcha_str = substr($random_str, 0, CAPTCHA_STRENGTH);

// Allocate new image
$width = (CAPTCHA_STRENGTH * 10)+10;
$height = 20;

$captcha_img =ImageCreate($width, $height);

// ALLOCATE COLORS
// Background color-black
$back_color = ImageColorAllocate($captcha_img, 0, 0, 0);

// Text color-white
$text_color = ImageColorAllocate($captcha_img, 255, 255, 255);

// Line color-red
$line_color = ImageColorAllocate($captcha_img, 255, 0, 0);

/****************************
*     DRAW BACKGROUND &    *
*           LINES          *
****************************/
// Fill background color
ImageFill($captcha_img, 0, 0, $back_color);

// Draw lines accross the x-axis
for($i = 0; $i < $width; $i += 5)
ImageLine($captcha_img, $i, 0, $i, 20, $line_color);

// Draw lines accross the y-axis
for($i = 0; $i < 20; $i += 5)
ImageLine($captcha_img, 0, $i, $width, $i , $line_color);

/****************************
*      DRAW AND OUTPUT     *
*          IMAGE           *
****************************/
// Draw the random string
ImageString($captcha_img, 5, 5, 2, $captcha_str, $text_color);

// Carry the data (KEY) through session
$_SESSION['key'] = $captcha_str;

// Send data type
header("Content-type: image/jpeg");

// Output image to browser
ImageJPEG($captcha_img);

// Free-Up resources
ImageDestroy($captcha_img);

How To Lock Your Computer With USB Drive

Tired of people starting your computer when you are not around and messing up custom settings? Wouldn’t it be cool if you could lock your computer by just removing your USB stick from it? I’ll show you how you can use your USB stick, Flash Drive or Pen Drive what ever you call it to lock your computer, among other things…


Boot Lock
 
This trick will allow you to use your USB to BOOT into Windows. If someone tries to start the computer without your USB stick, it will display boot errors. Before begin, you playing with the BIOS and boot files of your computer may result in you not being able to boot into your Windows partition; so continue at your own risk! 

Things you need: A 64MB or larger sized USB Stick, Windows Recovery Disk (just in case). Unhide hidden and protected files : Go to Tools > Options > View, check Show hidden files and un-check Hide protected system files.
  • From the drive where Windows is installed (normally C:\), copy the files boot.ini, ntdlr and NTDETECT.COM to your USB Stick.
  • Now, we need to go into your BIOS, so restart the computer and keep jabbing [F8] as soon as the computer starts.
  • Once in the BIOS, enable USB Drive as the first boot device. You might have to enable USB Legacy  Support on older BIOSes.
  • Restart your computer, if all goes well, you should be able to log into Windows. If not, then unplug the USB Stick, return to the BIOS and change the First Boot device to your hard disk drive and repeat the steps above.
  • Once you are logged into Windows, go to your Windows drive and rename boot.ini to boot.bak.
  • To check if you have setup everything correctly, eject your USB stick and reboot the computer. You should get error messages on the screen such as Invalid Boot.ini” or “Windows could not start”.

That's it !   :)

Google launches 'Swiffy' that Converts Flash to HTML5

Converting SWF files (the file format for Flash) to HTML 5 is now become possible with Swiffy.Googlelabs.com. 

Yes, Google's Swiffy makes Flash files HTML5 friendly, indirectly Google comes with Adobe Flash killer.. !

Using conversation tool, you will be able to reuse Flash content on devices which are not having Flash Player. You just need to upload SWF file to convert Flash Swf to HTML 5 video.


Swiffy.Googlelabs.com has been started in 2011. Swiffy is launched by Google Labs to convert Flash File to iPhone Friendly HTML5. Swiffy tool is like Adobe, called as WallyBy. The main difference between Swiffy and WallyBy is that Swiffy is web-based tool and code is made and compressed in a way which creates editing difficult, while Wallaby is a type of client which only works on Windows PC or Mac and the code is intended to be edited and reused. You can convert maximum 512 KB Flash files (.swf) into HTML 5 content.


How it works?


You don’t require registration to Convert Flash SWF to HTML5 Video at Google’s free online tool. To convert files into HTML5 Video, just upload flash file from your computer. Once you upload it, you can open flash files in any computer that does not contain flash player. You can also convert flash file into HTML, CSS, JavaScript, and SVG. Currently, the output of site only works on webkit-based browsers including Apple Safari and Google Chrome and Swiffy supports a division of ActionScript 2.0 and SWF 8. It works only with animation and content prepared using Flash 8.


Pros:

  • Convert Adobe Flash animation SWF Files into HTML5 easily
  • Open HTML 5 video on any computer which has no Flash Player

Cons:

  • Convert maximum 512 KB Flash files (.swf) into HTML 5 content

Swiffy vs. Wallaby


It should also be noted that Adobe launched a similar tool known as Wallaby in March. Like Swiffy, Wallaby converts Flash to HTML5, and again, mainly for the purpose of converting ads. Google explains the differences between the two programs in its FAQ:

Wallaby is an installable tool that converts .fla files, whereas Swiffy is a web-based tool that converts .swf files. Wallaby focuses on reusing parts of a Flash file in HTML, and thus produces code that can be edited by the developer, whereas Swiffy generates an efficient format that is not that easily editable.

For what's it's worth, Adobe says it's happy about Swiffy:

Adobe is pleased to see the Flash platform extended to devices which don't support the Flash player. The result is that anyone creating rich or interactive ads can continue to get all the authoring benefits of Flash Pro and have the flexibility to run the ad in the Flash Player or HTML depending on what's available on the system. Google and Adobe look forward to close collaboration around efforts like these.


Have you tried using Swiffy yet to convert any of your flash animations to HTML5?

Megabytes, Gigabytes, Terabytes... What Are They?

These terms are usually used in the world of computing to describe disk space, or data storage space, and system memory. For instance, just a few years ago we were describing hard drive space using the term Megabytes. Today, Gigabytes is the most common term being used to describe the size of a hard drive. In the not so distant future, Terabyte will be a common term. But what are they? This is where it gets quite confusing because there are at least three accepted definitions of each term.
According to the IBM Dictionary of computing, when used to describe disk storage capacity, a megabyte is 1,000,000 bytes in decimal notation. But when the term megabyte is used for real and virtual storage, and channel volume, 2 to the 20th power or 1,048,576 bytes is the appropriate notation. According to the Microsoft Press Computer Dictionary, a megabyte means either 1,000,000 bytes or 1,048,576 bytes. According to Eric S. Raymond in The New Hacker's Dictionary, a megabyte is always 1,048,576 bytes on the argument that bytes should naturally be computed in powers of two. So which definition do most people conform to?

When referring to a megabyte for disk storage, the hard drive manufacturers use the standard that a megabyte is 1,000,000 bytes. This means that when you buy an 80 Gigabyte Hard drive you will get a total of 80,000,000,000 bytes of available storage. This is where it gets confusing because Windows uses the 1,048,576 byte rule so when you look at the Windows drive properties an 80 Gigabyte drive will report a capacity of 74.56 Gigabytes and a 250 Gigabyte drive will only yield 232 Gigabytes of available storage space. Anybody confused yet? With three accepted definitions, there will always be some confusion so I will try to simplify the definitions a little.

The 1000 can be replaced with 1024 and still be correct using the other acceptable standards. Both of these standards are correct depending on what type of storage you are referring.

Processor or Virtual Storage

Disk Storage

· 1 Bit = Binary Digit
· 8 Bits = 1 Byte
· 1024 Bytes = 1 Kilobyte
· 1024 Kilobytes = 1 Megabyte
· 1024 Megabytes = 1 Gigabyte
· 1024 Gigabytes = 1 Terabyte
· 1024 Terabytes = 1 Petabyte
· 1024 Petabytes = 1 Exabyte
· 1024 Exabytes = 1 Zettabyte
· 1024 Zettabytes = 1 Yottabyte
· 1024 Yottabytes = 1 Brontobyte
· 1024 Brontobytes = 1 Geopbyte
· 1 Bit = Binary Digit
· 8 Bits = 1 Byte
· 1000 Bytes = 1 Kilobyte
· 1000 Kilobytes = 1 Megabyte
· 1000 Megabytes = 1 Gigabyte
· 1000 Gigabytes = 1 Terabyte
· 1000 Terabytes = 1 Petabyte
· 1000 Petabytes = 1 Exabyte
· 1000 Exabytes = 1 Zettabyte
· 1000 Zettabytes = 1 Yottabyte
· 1000 Yottabytes = 1 Brontobyte
· 1000 Brontobytes = 1 Geopbyte
 

This is based on the IBM Dictionary of computing method to describe disk storage - the simplest.

 

Now let's go into a little more detail.

Bit: A Bit is the smallest unit of data that a computer uses. It can be used to represent two states of information, such as Yes or No.

Byte: A Byte is equal to 8 Bits. A Byte can represent 256 states of information, for example, numbers or a combination of numbers and letters. 1 Byte could be equal to one character. 10 Bytes could be equal to a word. 100 Bytes would equal an average sentence.

Kilobyte: A Kilobyte is approximately 1,000 Bytes, actually 1,024 Bytes depending on which definition is used. 1 Kilobyte would be equal to this paragraph you are reading, whereas 100 Kilobytes would equal an entire page.

Megabyte: A Megabyte is approximately 1,000 Kilobytes. In the early days of computing, a Megabyte was considered to be a large amount of data. These days with a 500 Gigabyte hard drive on a computer being common, a Megabyte doesn't seem like much anymore. One of those old 3-1/2 inch floppy disks can hold 1.44 Megabytes or the equivalent of a small book. 100 Megabytes might hold a couple volumes of Encyclopedias. 600 Megabytes is about the amount of data that will fit on a CD-ROM disk.

Gigabyte: A Gigabyte is approximately 1,000 Megabytes. A Gigabyte is still a very common term used these days when referring to disk space or drive storage. 1 Gigabyte of data is almost twice the amount of data that a CD-ROM can hold. But it's about one thousand times the capacity of a 3-1/2 floppy disk. 1 Gigabyte could hold the contents of about 10 yards of books on a shelf. 100 Gigabytes could hold the entire library floor of academic journals.

Terabyte: A Terabyte is approximately one trillion bytes, or 1,000 Gigabytes. There was a time that I never thought I would see a 1 Terabyte hard drive, now one and two terabyte drives are the normal specs for many new computers.  To put it in some perspective, a Terabyte could hold about 3.6 million 300 Kilobyte images or maybe about 300 hours of good quality video. A Terabyte could hold 1,000 copies of the Encyclopedia Britannica. Ten Terabytes could hold the printed collection of the Library of Congress. That's a lot of data.

Petabyte: A Petabyte is approximately 1,000 Terabytes or one million Gigabytes. It's hard to visualize what a Petabyte could hold. 1 Petabyte could hold approximately 20 million 4-door filing cabinets full of text. It could hold 500 billion pages of standard printed text. It would take about 500 million floppy disks to store the same amount of data.

Exabyte: An Exabyte is approximately 1,000 Petabytes. Another way to look at it is that an Exabyte is approximately one quintillion bytes or one billion Gigabytes. There is not much to compare an Exabyte to. It has been said that 5 Exabytes would be equal to all of the words ever spoken by mankind.

Zettabyte: A Zettabyte is approximately 1,000 Exabytes. There is nothing to compare a Zettabyte to but to say that it would take a whole lot of ones and zeroes to fill it up.

Yottabyte: A Yottabyte is approximately 1,000 Zettabytes. It would take approximately 11 trillion years to download a Yottabyte file from the Internet using high-power broadband. You can compare it to the World Wide Web as the entire Internet almost takes up about a Yottabyte.

Brontobyte: A Brontobyte is (you guessed it) approximately 1,000 Yottabytes. The only thing there is to say about a Brontobyte is that it is a 1 followed by 27 zeroes!

Geopbyte: A Geopbyte is about 1000 Brontobytes! Not sure why this term was created. I'm doubting that anyone alive today will ever see a Geopbyte hard drive. One way of looking at a geopbyte is 15267 6504600 2283229 4012496 7031205 376 bytes!
Now you should have a good understanding of megabytes, gigabytes, terabytes and everything in between. Now if we can just figure out what a WhatsAByte is......:)

Was this helpful? Share it with your friends!