JohnGaughan.net
You are visitor number 927333 to visit this site.

String Hashing

Hashing, also called one-way encryption, is the process of converting a string into a new one based on an algorithm. There are three rules relating a string and its hash:

  1. Consistency: the same input string must always produce the same output string.
  2. Variation: a slight change in the input string must produce a large change in the output string.
  3. Uniqueness: two different input strings should not produce the same output string. This is unavoidable, but a good algorithm will minimize this.

This page uses PHP's built-in hashing functions. The algorithms used are:

  • MD5: this is a good algorithm in wide use for a variety of tasks. One good use is hashing passwords for an operating system. It is also in very wide use to generate checksums. This serves two purposes. First, you know if that file you downloaded is corrupted or not. Second, you know it has not been tampered with. MD5 hashes every single byte of the input string, no matter how large. It produces a string of length 32 characters that represents a 128 bit integer in hexadecimal format.
  • CRC32: originally designed for checksums on hard disk drives, in fact, it stands for "Cyclical Redundancy Check (32 bit)." it is usable for other tasks such as passwords. It is not as popular anymore because MD5 is generally faster and produces better hashes. This version produces a single 32 bit unsigned integer as a result.
  • SHA1: U.S. Secure Hash Algorithm 1. It is similar to MD5 but produces a string of length 40 characters, representing a 160 bit integer.

Plaintext



Site Copyright © 2006 John Gaughan
Background from Linux Propaganda
Send email to the Webmaster
Spamtrap
Validate This Site's Style Sheet
Validate This Page's XHTML Source