File: decode_teergrube.pl

package info (click to toggle)
sugarplum 0.9.10-18
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 228 kB
  • ctags: 15
  • sloc: perl: 384; sh: 50; makefile: 14
file content (49 lines) | stat: -rwxr-xr-x 1,255 bytes parent folder | download | duplicates (5)
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
#!/usr/bin/perl
# $Id: decode_teergrube.pl 44 2003-02-01 22:56:20Z aqua $
#
# Decodes teergrube-bait addresses emitted by sugarplum.  Addresses will be
# decoded either from the commandline or stdin.
#

grep($_ eq '-h',@ARGV) and do {
	print "usage: $0 addr1 addr2 ...\n",
		"Run without arguments, accepts a list of addresses on stdin,",
		" one per line.\n";
	exit;
};

if (@ARGV) {
	for (@ARGV) {
		print &decode_teergrube_address($_) || 'not a teergrube address',
			"\n";
	}
	exit;
}

while (<>) {
	chomp;
	print &decode_teergrube_address($_) || 'not a teergrube address',"\n";
}


sub decode_teergrube_address {
        my $uname = shift || return undef; $uname = lc $uname;
        $uname =~ /^([a-z])([a-z])([a-z]{8,})/ or return undef;
        my $permutation = ((ord($1)-97)<<4) | ord($2)-97;
        $uname = $3;
        my @addr;

        for (0..7) {
                if ($permutation & 1<<$_) {
                        $uname = substr($uname,0,$_).substr($uname,$_+1);
                }
        }
        @addr = ();
        for (0..3) {
                push @addr, ((ord(substr($uname,$_,1))-97<<4) |
                                (ord(substr($uname,$_+4,1))-97));
        }
        wantarray and return @addr;
        join('.',@addr);
}