Check It Yeah, It's On

23Mar/110

Empty Strings Are Hashable

This came to me as a bit of a surprise, but empty strings are hash-able! 🙂

So I decided to see the return on various hashing algorithms in PHP.

<?php
$emptyString = '';

print "md5:\t\t";
var_dump(md5($emptyString));
print "hash md5:\t";
var_dump(hash('md5', $emptyString));

print "\n";

print "sha1:\t\t";
var_dump(sha1($emptyString));
print "hash sha1:\t";
var_dump(hash('sha1', $emptyString));

print "\n";

// crc32 function returns differnt data type than 
// hash using the crc32 algorithm?
print "crc32:\t\t";
var_dump(crc32($emptyString));
print "hash crc32:\t";
var_dump(hash('crc32', $emptyString));

print "\n";

print "ripemd128:\t";
var_dump(hash('ripemd128', $emptyString));

print "iger128,3:\t";
var_dump(hash('tiger128,3', $emptyString));

print "snefru:\t\t";
var_dump(hash('snefru', $emptyString));

print "gost:\t\t";
var_dump(hash('gost', $emptyString));

print "adler32:\t";
var_dump(hash('adler32', $emptyString));

print "haval128,3:\t";
var_dump(hash('haval128,3', $emptyString));

print "whirlpool:\t";
var_dump(hash('whirlpool', $emptyString));

Output:

md5:		string(32) "d41d8cd98f00b204e9800998ecf8427e"
hash md5:	string(32) "d41d8cd98f00b204e9800998ecf8427e"
 
sha1:		string(40) "da39a3ee5e6b4b0d3255bfef95601890afd80709"
hash sha1:	string(40) "da39a3ee5e6b4b0d3255bfef95601890afd80709"
 
crc32:		int(0)
hash crc32:	string(8) "00000000"
 
ripemd128:	string(32) "cdf26213a150dc3ecb610f18f6b38b46"
iger128,3:	string(32) "24f0130c63ac933216166e76b1bb925f"
snefru:		string(64) "8617f366566a011837f4fb4ba5bedea2b892f3ed8b894023d16ae344b2be5881"
gost:		string(64) "ce85b99cc46752fffee35cab9a7b0278abb4c2d2055cff685af4912c49490f8d"
adler32:	string(8) "01000000"
haval128,3:	string(32) "c68f39913f901f3ddf44c707357a7d70"
whirlpool:	string(128) "19fa61d75522a4669b44e39c1d2e1726c530232130d407f89afee0964997f7a73e83be698b288febcf88e3e03c4f0757ea8964e59b63d93708b138cc42a66eb3"
Filed under: Code Leave a comment
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment

No trackbacks yet.