linux - hash algorithm

A Hashing Algorithm is a mathematical formula that takes a Message of arbitrary length as input and produces as output a representational sample of the original data.

For instance, a rudimentary example of a hashing algorithm is simply adding up all the letter values of a particular message. (A=1, B=2, C=3, etc…):

 

linux - hash algorithm

 

 

 

The result of a hashing algorithm is called a message Digest (or sometimes Checksum, or Fingerprint). The result of our example hashing on the original message of hello was 52. If someone were to change our original message and process it through the same hashing algorithm, the result would be different:

linux - hash algorithm

 

 

By comparing the message digests of each calculation, it is easy to determine that our message has changed.

Obviously, the Hashing algorithm used in the example is full of flaws. There are many words that when processed through the example algorithm that might result in the same Digest. Had the original Message been changed to cellt, the resulting digest would still be 52, and we would be unaware that the original Message had been altered.

 

 

 

Hashing Demonstration with Linux

 

The standard Linux terminal typically comes with at least two of the Hashing Algorithms mentioned above:  MD5 and SHA1. You can use the echo command along with md5sum or sha1sum to run either algorithm on a string of text:

 

 

linux - hash algorithm

 

上一篇:Verilog--数据类型


下一篇:consist hashing