General Hashing

crc32($s) returns an integer which is the cyclic-redundancy-checksum polynomial of $s. It is 32 bits long. crypt($s1[,$s2]) returns a hashed string of $s1, using the standard Unix DES-based algorithm. $s2 is the salt string to base the hashing on. md5 ($s[,$b=false]) returns the MD5 hash of $s, which is a string storing a 32-character hexadecimal number. If $b is true, the hash is in raw binary format with a length of 16. md5_file($s [,$b=false]) is similar to md5() except that instead of a string, $s is the name of the file to be hashed. sha1($s [,$b=false]) returns the sha1 hash of $s, which is a string storing a 40-character hexadecimal number. If $b is true, the hash is in raw binary format with a length of 20. sha1_file ($s[,b]) is similar to sha1() except that instead of a string, $s is the name of the file to be hashed.

RESETRUNFULL
<!DOCTYPE html><html><head></head>
<body><?php

$s = "hello world";
echo crc32($s)."<br />";
echo crypt($s)."<br />"; // different each time
echo crypt($s,"ABC")."<br />";
echo md5($s)."<br />";
echo sha1($s)."<br />";

?></body></html>
str_rot13($s) returns a copy of $s with ROT13 performed. ROT13 encoding shifts every letter by 13 places in the alphabet. Passing an encoded string as an argument will return the original version. bin2hex($s) returns a string containing the hexadecimal representation of $s. hex2bin($s) is the reverse of bin2hex(). convert_uuencode($s) returns a string that is $s encoded using the uuencode algorithm. Uuencode translates all strings into printable characters, making them safe for network transmissions. Uuencoded data is about 35% larger than the original. convert_uudecode($s) is the reverse of convert_uuencode(). quoted_ printable_encode($s) returns a quoted printable string created according to RFC2045, Section 6.7, from a 8 bit string. quoted_printable_decode($s)  is the reverse of quoted_printable_encode().

RESETRUNFULL
<!DOCTYPE html><html><head></head>
<body><?php

$s = "PHP 5.4.0\n\r";
echo str_rot13($s)."<br />";
echo str_rot13(str_rot13($s))."<br />";
echo bin2hex($s)."<br />";
echo hex2bin(bin2hex($s))."<br />";
echo convert_uuencode($s)."<br />";
echo convert_uudecode(convert_uuencode($s))."<br />";
echo quoted_printable_encode($s)."<br />";
echo quoted_printable_decode( quoted_printable_encode($s))."<br />";

?></body></html>
hash_algos() returns an array containing the names of all registered hashing algorithms.

<?php
print_r(hash_algos());
?>

Array ( [0] => md2 [1] => md4 [2] => md5 [3] => sha1 [4] => sha224 [5] => sha256 [6] => sha384 [7] => sha512 [8] => ripemd128 [9] => ripemd160 [10] => ripemd256 [11] => ripemd320 [12] => whirlpool [13] => tiger128,3 [14] => tiger160,3 [15] => tiger192,3 [16] => tiger128,4 [17] => tiger160,4 [18] => tiger192,4 [19] => snefru [20] => snefru256 [21] => gost [22] => adler32 [23] => crc32 [24] => crc32b [25] => fnv132 [26] => fnv164 [27] => joaat [28] => haval128,3 [29] => haval160,3 [30] => haval192,3 [31] => haval224,3 [32] => haval256,3 [33] => haval128,4 [34] => haval160,4 [35] => haval192,4 [36] => haval224,4 [37] => haval256,4 [38] => haval128,5 [39] => haval160,5 [40] => haval192,5 [41] => haval224,5 [42] => haval256,5 )
hash_file($s1, $s2 [,$b=false]) returns a hash for string $s2 using algorithm $s1. hash_file($s1, $s2 [,$b=false]) returns a hash for file $s2 using algorithm $s1. If $b is true, raw binary data is output. hash_algos() returns an array containing the names of all registered hashing algorithms.

RESETRUNFULL
<?php
echo hash('sha1','Please code PHP well.')."<br/>";
file_put_contents('eg.txt', 'Please code PHP well.');
echo hash_file('sha1', 'eg.txt');
?>
hash_init($s1 [, $i=0 [, $s2=NULL]]) initializes an incremental hashing context, using algorithm $s1. $i can be HASH_HMAC. If $i is HASH_HMAC, $s2 specifies the secret key. hash_update($r, $s) pumps string $s into active hashing context $r. hash_update_file($r, $s) pumps data from file $s into active hashing context $r. hash_final($r, $b=false) finalizes an incremental hash (context $r) and returns the resulting digest. If $b is true, raw binary data is output.

RESETRUNFULL
<?php
$c = hash_init('md5');
hash_update($c, 'PHP is really fun.');
hash_update($c, 'Do you agree?');
hash_update_file($c,'eg.txt');
echo hash_final($c);
?>