🐪 BDecode-beautyfied.pm (Perl) 2.4 KB 2006-10-24
Perl module for BDecode beautyfied
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52 | #########################################
##### Author: Sebastian Enger / B.Sc
##### CopyRight: Sebastian Enger
##### LastModified 16.07.2006
##### Function:
##### Todo:
########################################
# - Based on vesion 0.1.0.3-BETA of TorrentSpy from http://torrentspy.sf.net/
# Original copyright unknown, SourceForge claims "MIT License"
package TorrentIndexer::BITTORRENT::BDecode;
use Carp;
use strict;
sub bdecode() {
my ($dataref) = shift;
my $p = 0;
if ( ref($dataref) ne 'SCALAR') {
return benc_parse_hash(\$dataref,\$p);
} elsif ( ref($dataref) eq 'SCALAR') {
return benc_parse_hash($dataref,\$p);
};
}; # sub bdecode
sub benc_parse_hash() {
my $data = shift;
my $p = shift;
my $c = substr(${$data},${$p},1);
my $r = undef;
if($c eq 'd') { # hash
# print "Found a hash\n";
%{$r} = ();
++${$p};
while((${$p} < length(${$data})) && (substr(${$data}, ${$p}, 1) ne 'e')) {
my $k = benc_parse_string($data, $p);
my $start = ${$p};
$r->{'_' . $k . '_start'} = ${$p} if($k eq 'info');
my $v = benc_parse_hash($data, $p);
$r->{'_' . $k . '_length'} = ($$p - $start) if($k eq 'info');
... [truncated, 75 more lines] ...
|
{
"@context": "https://schema.org",
"@type": "SoftwareSourceCode",
"name": "BDecode-beautyfied.pm",
"description": "Perl module for BDecode beautyfied",
"dateModified": "2006-10-24",
"dateCreated": "2025-03-23",
"contentSize": "2.4 KB",
"contentUrl": "https://www.artikelschreiber.com/opensource/torrentindexer/BitTorrent/BDecode-beautyfied.pm",
"encodingFormat": "text/x-perl",
"programmingLanguage": {
"@type": "ComputerLanguage",
"name": "Perl"
},
"codeRepository": "https://www.artikelschreiber.com/opensource/torrentindexer/BitTorrent/"
}
🐪 BDecode.pm (Perl) 2.2 KB 2006-10-24
Perl module for BDecode
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52 | # - Based on vesion 0.1.0.3-BETA of TorrentSpy from http://torrentspy.sf.net/
# Original copyright unknown, SourceForge claims "MIT License"
package TorrentIndexer::BITTORRENT::BDecode;
use Carp;
use base 'Exporter';
use strict;
our @EXPORT_OK = qw(bdecode);
sub bdecode {
my ($dataref) = @_;
unless(ref($dataref) eq 'SCALAR') {
die('Function bdecode takes a scalar ref!');
} # unless
my $p = 0;
return benc_parse_hash($dataref,\$p);
} # sub bdecode
sub benc_parse_hash {
my ($data, $p) = @_;
my $c = substr($$data,$$p,1);
my $r = undef;
if($c eq 'd') { # hash
# print "Found a hash\n";
%{$r} = ();
++$$p;
while(($$p < length($$data)) && (substr($$data, $$p, 1) ne 'e')) {
my $k = benc_parse_string($data, $p);
my $start = $$p;
$r->{'_' . $k . '_start'} = $$p if($k eq 'info');
my $v = benc_parse_hash($data, $p);
$r->{'_' . $k . '_length'} = ($$p - $start) if($k eq 'info');
# print "\t{$k} => $v\n";
$r->{$k} = $v;
} # while
++$$p;
# print "End of Hash\n";
} elsif($c eq 'l') { # list
@{$r} = \();
++$$p;
# print "Found a list\n";
while(substr($$data, $$p, 1) ne 'e') {
push(@{$r},benc_parse_hash($data, $p));
# print "\t[@{$r}] = $$r[-1]\n";
} # while
++$$p;
} elsif($c eq 'i') { # number
$r = 0;
my $c;
++$$p;
... [truncated, 38 more lines] ...
|
{
"@context": "https://schema.org",
"@type": "SoftwareSourceCode",
"name": "BDecode.pm",
"description": "Perl module for BDecode",
"dateModified": "2006-10-24",
"dateCreated": "2025-03-23",
"contentSize": "2.2 KB",
"contentUrl": "https://www.artikelschreiber.com/opensource/torrentindexer/BitTorrent/BDecode.pm",
"encodingFormat": "text/x-perl",
"programmingLanguage": {
"@type": "ComputerLanguage",
"name": "Perl"
},
"codeRepository": "https://www.artikelschreiber.com/opensource/torrentindexer/BitTorrent/"
}
🐪 BDecode1.pm (Perl) 2.1 KB 2003-06-15
Perl module for BDecode1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52 | # - Based on vesion 0.1.0.3-BETA of TorrentSpy from http://torrentspy.sf.net/
# Original copyright unknown, SourceForge claims "MIT License"
package BitTorrent::BDecode;
use Carp;
use base 'Exporter';
use strict;
our @EXPORT_OK = qw(bdecode);
sub bdecode {
my ($dataref) = @_;
unless(ref($dataref) eq 'SCALAR') {
die('Function bdecode takes a scalar ref!');
} # unless
my $p = 0;
return benc_parse_hash($dataref,\$p);
} # sub bdecode
sub benc_parse_hash {
my ($data, $p) = @_;
my $c = substr($$data,$$p,1);
my $r = undef;
if($c eq 'd') { # hash
# print "Found a hash\n";
%{$r} = ();
++$$p;
while(($$p < length($$data)) && (substr($$data, $$p, 1) ne 'e')) {
my $k = benc_parse_string($data, $p);
my $start = $$p;
$r->{'_' . $k . '_start'} = $$p if($k eq 'info');
my $v = benc_parse_hash($data, $p);
$r->{'_' . $k . '_length'} = ($$p - $start) if($k eq 'info');
# print "\t{$k} => $v\n";
$r->{$k} = $v;
} # while
++$$p;
# print "End of Hash\n";
} elsif($c eq 'l') { # list
@{$r} = \();
++$$p;
# print "Found a list\n";
while(substr($$data, $$p, 1) ne 'e') {
push(@{$r},benc_parse_hash($data, $p));
# print "\t[@{$r}] = $$r[-1]\n";
} # while
++$$p;
} elsif($c eq 'i') { # number
$r = 0;
my $c;
++$$p;
... [truncated, 38 more lines] ...
|
{
"@context": "https://schema.org",
"@type": "SoftwareSourceCode",
"name": "BDecode1.pm",
"description": "Perl module for BDecode1",
"dateModified": "2003-06-15",
"dateCreated": "2025-03-23",
"contentSize": "2.1 KB",
"contentUrl": "https://www.artikelschreiber.com/opensource/torrentindexer/BitTorrent/BDecode1.pm",
"encodingFormat": "text/x-perl",
"programmingLanguage": {
"@type": "ComputerLanguage",
"name": "Perl"
},
"codeRepository": "https://www.artikelschreiber.com/opensource/torrentindexer/BitTorrent/"
}
🐪 Bencode-unimportant.pm (Perl) 4.1 KB 2006-10-23
Perl module for Bencode unimportant
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52 | #!/usr/bin/perl -w
package Convert::Bencode;
# package BitTorrent::BDecode;
=head1 NAME
Convert::Bencode - Functions for converting to/from bencoded strings
=head1 SYNOPSIS
use Convert::Bencode qw(bencode bdecode);
my $string = "d4:ainti12345e3:key5:value4:type4:teste";
my $hashref = bdecode($string);
foreach my $key (keys(%{$hashref})) {
print "Key: $key, Value: ${$hashref}{$key}\n";
}
my $encoded_string = bencode($hashref);
print $encoded_string."\n";
=head1 DESCRIPTION
This module provides two functions, C<bencode> and C<bdecode>, which
encode and decode bencoded strings respectivly.
=head2 Encoding
C<bencode()> expects to be passed a single value, which is either a scalar,
a arrary ref, or a hash ref, and it returns a scalar containing the bencoded
representation of the data structure it was passed. If the value passed was
a scalar, it returns either a bencoded string, or a bencoded integer (floating
points are not implemented, and would be returned as a string rather than a
integer). If the value was a array ref, it returns a bencoded list, with all
the values of that array also bencoded recursivly. If the value was a hash ref,
it returns a bencoded dictionary (which for all intents and purposes can be
thought of as a synonym for hash) containing the recursivly bencoded key and
value pairs of the hash.
=head2 Decoding
C<bdecode()> expects to be passed a single scalar containing the bencoded string
to be decoded. Its return value will be either a hash ref, a array ref, or a
scalar, depending on whether the outer most element of the bencoded string
was a dictionary, list, or a string/integer respectivly.
=head1 SEE ALSO
... [truncated, 125 more lines] ...
|
{
"@context": "https://schema.org",
"@type": "SoftwareSourceCode",
"name": "Bencode-unimportant.pm",
"description": "Perl module for Bencode unimportant",
"dateModified": "2006-10-23",
"dateCreated": "2025-03-23",
"contentSize": "4.1 KB",
"contentUrl": "https://www.artikelschreiber.com/opensource/torrentindexer/BitTorrent/Bencode-unimportant.pm",
"encodingFormat": "text/x-perl",
"programmingLanguage": {
"@type": "ComputerLanguage",
"name": "Perl"
},
"codeRepository": "https://www.artikelschreiber.com/opensource/torrentindexer/BitTorrent/"
}
🐪 Bencode.pm (Perl) 4.1 KB 2006-10-23
Perl module for Bencode
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52 | #!/usr/bin/perl -w
package Convert::Bencode;
# package BitTorrent::BDecode;
=head1 NAME
Convert::Bencode - Functions for converting to/from bencoded strings
=head1 SYNOPSIS
use Convert::Bencode qw(bencode bdecode);
my $string = "d4:ainti12345e3:key5:value4:type4:teste";
my $hashref = bdecode($string);
foreach my $key (keys(%{$hashref})) {
print "Key: $key, Value: ${$hashref}{$key}\n";
}
my $encoded_string = bencode($hashref);
print $encoded_string."\n";
=head1 DESCRIPTION
This module provides two functions, C<bencode> and C<bdecode>, which
encode and decode bencoded strings respectivly.
=head2 Encoding
C<bencode()> expects to be passed a single value, which is either a scalar,
a arrary ref, or a hash ref, and it returns a scalar containing the bencoded
representation of the data structure it was passed. If the value passed was
a scalar, it returns either a bencoded string, or a bencoded integer (floating
points are not implemented, and would be returned as a string rather than a
integer). If the value was a array ref, it returns a bencoded list, with all
the values of that array also bencoded recursivly. If the value was a hash ref,
it returns a bencoded dictionary (which for all intents and purposes can be
thought of as a synonym for hash) containing the recursivly bencoded key and
value pairs of the hash.
=head2 Decoding
C<bdecode()> expects to be passed a single scalar containing the bencoded string
to be decoded. Its return value will be either a hash ref, a array ref, or a
scalar, depending on whether the outer most element of the bencoded string
was a dictionary, list, or a string/integer respectivly.
=head1 SEE ALSO
... [truncated, 125 more lines] ...
|
{
"@context": "https://schema.org",
"@type": "SoftwareSourceCode",
"name": "Bencode.pm",
"description": "Perl module for Bencode",
"dateModified": "2006-10-23",
"dateCreated": "2025-03-23",
"contentSize": "4.1 KB",
"contentUrl": "https://www.artikelschreiber.com/opensource/torrentindexer/BitTorrent/Bencode.pm",
"encodingFormat": "text/x-perl",
"programmingLanguage": {
"@type": "ComputerLanguage",
"name": "Perl"
},
"codeRepository": "https://www.artikelschreiber.com/opensource/torrentindexer/BitTorrent/"
}