So you heard the term hashing, but unless you have a background in computer science, you probably aren’t quite sure what that means. Let’s take a look at hashing in terms of cooking. When we hash something for example, like hash browns, we are chopping up potatoes and mixing them together to create the delicious breakfast favourite hash browns. Similar to this process, computers take hash functions of any length and use a mathematical formula to do just that. Hashing is the process of taking one given key and converting it into another value. A hash function is utilized to create new value with a mathematical logarithm. The result of a hash function is known as a hash value or hash. It is important to use a one-way hashing algorithm when using a hash function so that it can not be changed back to the original key. However, collisions can occur which is when two keys create the same hash.
Below are several important terms defined that deal with hashing.
- Key: any unique value that can be changed that is used in hashing. It can be a string, integer or tuple.
- Hash Key: returned from a hash function as a numeric value.
- Hash Function: the process in which a key is changed to a hash key.
What is Hashing Used For?
The most common use of hashing is for the implementation of hash tables. A hash table takes keys or valued pairs and stores them in a list where any element can reach them. It acts as something like an index. There is no limit to how many keys or valued pairs there are. A hash function can be used to map the keys to the table’s size. The hash value then acts as an index for a given element.
Another use of hashing is encryption. For example, passwords can be saved in the form of their hashes so that if a breach occurs, plain text passwords can not be accessed. The most popular cryptographic hashes include MD5, SHA-1 and SHA-2. For example, if a hacker were to reach out and discover the original string for “John’s Wallet ID Number”, they could take this information and use it for their advantage. However, if they were to reach out and discover a hash value instead, that information would be rendered useless to them, unless of course they also had the key to solve it.
Hashing is beneficial when it comes to data compression, though it is not compression itself. That is an entirely different matter. In terms of compression, hashing is beneficial in the sense that it can take a larger data set and shrink it to a smaller size that is much more manageable. Let’s use our example “John’s Wallet ID Number” again. If this was written 40 times, 100 times or even 500 times through an entire database, it could be taken and converted to a shorter string resulting in smaller space being used and more memory space.
Hashing can also be used when it comes to data retrieval. Let’s use the Dewey decimal system, a key library innovation from the 20th century, as a comparison and example. Retrieving a hash value is similar to when you retrieve a Dewey decimal number for a book. When searching for a book, instead of using the book’s title, you use the Dewey decimal system identification or address for that book along with a few important alphanumeric characters derived from the book’s title and author’s name. Similar to how this system helps libraries, hashing in computer science allows original data strings and data assets to be shrunk to short alphanumeric hash keys. This helps engineers not only by saving space but being able to do several key security enhancements.
Another valuable benefit of hashing is the prevention of tampering. The way this is accomplished is an original file will create a hash. This hash is kept with the file data. They are sent together. Once received, the receiving party can check to see if a file has been compromised. If changes were made to a file, the hash will show that has occurred.