eD2k hash generation in PHP

January 12th, 2010

Spent some time last night fixing a function I wrote ages ago to generate an ed2k hash for a given file. I then failed to test and fix it with regard to files larger than the chunk size (9,728,000 bytes).

Here’s an updated version:

function ed2kHash_file ($name) {
	# Calculates eDonkey2000 hash for any given file
	# By: Tom Higginson
	# Date: 9th January 2008
	# Modified: 11th January 2010
	# License: Public domain

	$chunkSize = 9728000;
	$md4str = '';

	if( !file_exists( $name ) ) {
		return false;
	}

	if( filesize( $name ) <= $chunkSize ) {
		return hash_file( 'md4', $name );
	} else {
		$fH = fopen( $name, 'r' );
		while( !feof( $fH ) ) {
			$md4str .= hash( 'md4', fread( $fH, $chunkSize ), true );
		}

		fclose( $fH );

		return hash( 'md4', $md4str );
	}
}

Here's some more about the eD2k hash: http://en.wikipedia.org/wiki/Ed2k_URI_scheme

Blog 2.0

June 14th, 2009

I’ve decided to start this blog again after accidentally joining a discussion about using social media for Shift Time festival, happening in Shrewsbury later this month.

I’ve nothing to post about right now except I’m about to listen to Fanfarlo album, which I bought because they’re currently selling whole album by download for $1.

Also looking at various bicycles in order to buy one tomorrow afternoon if I manage to pass my driving test, which I’m currently also studying for.

Fun :)