i needed a way to generate ed2k urls based on existing files on my harddrive.
ed2k link looks like this:
filename and filesize are of course known, but what about checksum? i tried to find some ready program to calculate them, but failed. it might be because i spent something like 3 minutes on it, but anyway – i didn't find it. so i tried to find algorithm description.
luckily there is a nice algorithms description. algorithms, as there apparently are two separate algorithms, not fully compatible with each other.
based on the information i was able to write a short perl script which does the job:
=> cat ed2ksum.pl #!/usr/bin/perl -l use Digest::MD4 qw(md4 md4_hex);open$f,pop or die$!;$c.=md4$b while sysread$f,$b,9728000;print uc md4_hex$c
yes, it is unreadable. but it works. first version was longer (about 15 lines), but then i decided to try to make it shorter. and shorter. and then even shorter. most probably it is not the shortest possible way, but i'm safisfied with it.
how does it work? simply:
=> ./ed2ksum.pl Slony-I-concept.pdf E8715CD212CD75E0EE4B6C526D5BF36A
hope you'll find it useful.