Hashes & Co.

Hashes & Co.

Oktober 28, 2016 Software-Development 0

Module 1

Let’s start to look at hashing and hash functions. The first thing on the agenda should be some definition of what this thing called hashing is and what common hash functions are…

Generally said, a hashfunction is something that converts a variable length input to a fixed length value. Some call this action a data fingerprint.
See how the output length stays fix:

 

One of the important things is that the created (output) value can’t be used to recreate the previously taken input. So a hash function is one way. It is easy to compute a hash, but you can’t reverse it.

Example:
In it’s simpliest form a hash function could generate a counter for each character found in a line of a password phrase.

 

 

 

 

 

 

 


 

 

In the example above the output of the hash function would be 8 3 13 54 or any other format representing these integer values (Hex, Octal, Binary…). Ok, this is a very simple application. A password with an input length of 8, 3, 13, 54 can be anything. Assume you would try AnyWords instead of SomeText (this has the same number of characters: 8) as the first line of the password phrase. It would be accepted!

Here is some code to visualize the example:

1
2
3
4
5
6
7
8
9
10
11
12
13
private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
{
var textBox = sender as TextBox;
Input = textBox.Text; //Any text input;

SHA512Managed hashFunction = new SHA512Managed();

//SHA512 returns 512 bits (64 byte) for the hash
byte[] hash = hashFunction.ComputeHash(Encoding.UTF8.GetBytes(Input));

//Converts the 64 byte hash into a string hex representation of byte values
Output = BitConverter.ToString(hash).Replace("-", "");
}

In the next module I will write about the performance of the various hash functions…