文章出处:SUPERHEI
复制内容到剪贴板
代码:
#!/usr/bin/perl
#int2hex & int2asc
#codz by superhei
#welcome to [url]http://www.darkne2s.org[/url] & [url]http://www.4ngel.net[/url]
$ARGC = @ARGV;
if ($ARGC != 2) {
print "Usage: $0 <option> <string>\n";
print " 1:2hex \n";
print " 2:2asc \n";
exit;
}
$option = shift;
$string = shift;
if ($option == 1) {
@todo = split("",$string);
@todo2 = map(ord($_),@todo);
@todo3 = map(&int2hex($_),@todo2);
print "0x";
print @todo3;
}elsif ($option == 2) {
@char = unpack('C*', $string);
$asc=join(",",@char);
print $asc;}
else {
print "Invalid option!\n";
exit;
}
#codz by analysist
sub int2hex {
my ($int) = @_;
push(@int,int($int/16));
push(@int,int($int%16));
@xxx = (10,11,12,13,14,15);
@yyy = (A,B,C,D,E,F);
$x = 0;
while ($x < @int) {
$y = 0;
while ($y < @xxx) {
if ($int[$x] eq $xxx[$y]) {
push(@hex,$yyy[$y]);
last;
}
$y++;
}
if ($hex[$x] eq "") {
push(@hex,$int[$x]);
}
$x++;
}
$hex = join("",@hex);
undef @int;
undef @hex;
return $hex;
}