#!/usr/bin/perl $|++; use Bencode qw/bdecode/; use Digest::SHA1 qw(sha1_hex); my $base = shift @ARGV; my $torrent = "$base.torrent"; open( T, $torrent) or die $!; my $torrent_data = join '', ; close( T ); my $metainfo = bdecode( $torrent_data ); my $file_name = "$base/" . $metainfo->{'info'}->{'name'}; my $file_length = $metainfo->{'info'}->{'length'}; my $piece_length = $metainfo->{'info'}->{'piece length'}; my $pieces = $metainfo->{'info'}->{'pieces'}; my @pieces = (); my $offset = 0; while ( $offset < length( $pieces ) ) { my $piece = substr( $pieces, $offset * 20, 20 ); push @pieces, $piece; $pieces = substr($pieces,20); } my $path = "C:/users/caleb/desktop/"; open( F, "<", $path . $file_name ) or die "Cannot open file - (Tried to open $path$file_name and got this error : $!\n"; print "MyFile - $path$file_name\n"; my $counted = 0; foreach my $p ( @pieces ) { $counted++; $p =~ s/(.)/sprintf("%02x",ord($1))/egs; print "[dothis:] Piece $counted: $p \n"; my ($buf, $data, $n); binmode F; $excount; while ($n = read (F, $data, $piece_length) != 0) { $excount++; print "[dothat] Hash2:" . sha1_hex($data) . "\n\n"; $countpieces = $#pieces; print "Piece Count: $countpieces\n"; print "N = $n\n"; print "DataCount:" . length($data) . "\n"; print "Count:" . $excount . "\n"; print "Counted: $counted\n"; print "Hash:" . sha1_hex($p) . "\n\n"; print "HashMatch!\n" if ($p eq sha1_hex($data)); print "No Match!\n" if ($p ne sha1_hex($data)); print "----------------------\n"; $buf .= $data; } } close( F ); #### MyFile - C:/users/caleb/desktop/test/testfile.mp3 [dothis:] Piece 1: c0ba18a0db37c7d6c8c4c267355627dd5b98473f [dothat] Hash2:c0ba18a0db37c7d6c8c4c267355627dd5b98473f Piece Count: 1192 N = 1 DataCount:32768 Count:1 Counted: 1 Hash:ab50b58f162501072fe1ad6c2120e92eba500afd HashMatch! ---------------------- [dothat] Hash2:d902928543f3e0aa4092534c075957e800a5e3c6 Piece Count: 1192 N = 1 DataCount:32768 Count:2 Counted: 1 Hash:ab50b58f162501072fe1ad6c2120e92eba500afd No Match! ---------------------- ....(Edited to not include 1192 data entries).. .... .... [dothat] Hash2:5402f35d944e62bfc750e5a8b5f3be6e84f6cb3b Piece Count: 1192 N = 1 DataCount:31663 Count:1193 Counted: 1 Hash:ab50b58f162501072fe1ad6c2120e92eba500afd No Match! ---------------------- [dothis:] Piece 2: d902928543f3e0aa4092534c075957e800a5e3c6 [dothis:] Piece 3: 1bf32c88a4d6ba89223dfbc680a310c805e54e66