HASH
A HASH function is any function that can be used to map data of arbitrary size to data of a fixed size.
The values returned by a HASH function are called HASH values, HASH codes, digests, or simply hashes.
HASH functions are often used in combination with a HASH table, a common data structure used in computer software for rapid data lookup.
HASH functions accelerate table or database lookup by detecting duplicated records in a large file.
One such application is finding similar stretches in DNA sequences.
They are also useful in cryptography.
A cryptographic HASH function allows one to easily verify that some input data maps to a given HASH value, but if the input data is unknown, it is deliberately difficult to reconstruct it, (or any equivalent alternatives), by knowing the stored HASH value.
This is used for assuring integrity of transmitted data, and is the building block for HMACs, which provide message authentication.
HASH functions are related to, (and often confused with), checksums, check digits, fingerprints, lossy compression, randomization functions, error-correcting codes, and ciphers.
Although the concepts overlap to some extent, each one has its own uses and requirements and is designed and optimized differently.
The HashKeeper database maintained by the American National Drug Intelligence Center, for instance, is more aptly described as a catalogue of file fingerprints than of HASH values.
From Wikipedia, the free encyclopedia
<?php
str md5 ( str $str [, bool $raw_output = FALSE ] )
where,
$str = STRING to calculate the validation key
$raw_output = To control the md5 value output
( SEE the below TABLE )
?>
$str
STRING to calculate the md5 validation key.
$raw_output
VALUE |
MEANING |
CHARACTERS |
FALSE |
md5 HASH HEXADECIMAL |
32 |
TRUE |
md5 HASH RAW BINARY |
16 |
ed48 |
EXERCISE
<?php
$str2md5 = "Love's not time's fool,
though rosy lips and cheeks within
his bending sickle's compass come;
or bends with the remover to remove.
Let me not to the marriage of true
minds if this be error and upon me
proved, oh, no, it is an ever fixed mark.
Which alters when it alteration finds,
it is the star to every wand'ring bark,
admit impediments; love is not love.";
$strmd5H = md5($str2md5);
$strmd5B = md5($str2md5, true);
echo 'MD5 HASH (32) = <br>' . $strmd5H;
echo '<br><br>MD5 HASH (16) = <br>' . $strmd5B;
?>
EXERCISE
<?php
$fls = __DIR__ . '/md502.txt';
$str2md5 = "Love's not time's fool,
though rosy lips and cheeks within
his bending sickle's compass come;
or bends with the remover to remove.
Let me not to the marriage of true
minds if this be error and upon me
proved, oh, no, it is an ever fixed mark.
Which alters when it alteration finds,
it is the star to every wand'ring bark,
admit impediments; love is not love.";
$yn = file_put_contents($fls, $str2md5);
if($yn == true)
{
echo 'Text file WAS SAVED as expected!<br><br>';
}
else
{
echo 'Text file WAS NOT SAVED as expected!<br><br>';
}
$strmd5H = md5($str2md5);
$strmd5B = md5($str2md5, true);
echo 'MD5 HASH (32) = <br>' . $strmd5H;
echo '<br><br>MD5 HASH (16) = <br>' . $strmd5B;
unlink($fls);
?>