把二进制翻译成中文/英文

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

#!/usr/bin/perl -w
#use diagnostics;
sub bin2cn{
	die "Error:1001:bin2cn\n" if chop($_[0]) eq "";
	@hexi = &bin2hex($_[0]);
	while(@hexi){
		$q=shift @hexi if @hexi;#noting
		$temp=&hex2int($q);
		$q=shift @hexi if @hexi;
		$temp=$temp*16+&hex2int($q);
		push @cni, chr($temp);
	}
	join '', @cni
}

sub bin2hex{
	my @binarr=('0000','0001','0010','0011','0100','0101','0110','0111','1000','1001','1010','1011','1100','1101','1110','1111');
	my @hexarr=("0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F");

	if(length($_[0]) % 4 ){
		my @in = &split4($_[0]);
		while(my $ta=shift @in){
			for (0..15){
				push @re, $hexarr[$_] if ($binarr[$_] eq $ta) ;
			}
		}
		@re
	}else{
		print "Error:1001:bin2hex\n";
		exit
	}
}
sub hex2bin{
	my @binarr=('0000','0001','0010','0011','0100','0101','0110','0111','1000','1001','1010','1011','1100','1101','1110','1111');
	my @hexarr=('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
	my @in = split //, $_[0];
	while(@in){
		my $tai=shift @in;#noting
		for (0..15){
			push @reo, $binarr[$_] if ($hexarr[$_] eq $tai);
		}
	}
	join '', @reo
}
sub split4{
	my $ini = $_[0];
	push @res, substr($ini,$_,4) for (grep {$_ % 4 == 0 } 0..length($ini));
	@res
}

sub hex2int{
	if ($_[0] =~ /^[ABCDEF]$/){
		ord($_[0])-65+10;
	}elsif($_[0] =~ /^[0123456789]$/){
		ord($_[0])-48;
	}else{
		print "\nError: 1001:hex2int\n";
		exit
	}
}
#open IN, "<./binaryfile";
#my $tee= <IN>;
#my @sd=&split4($tee);
#print "SS: @sd\n";
#print "OO: ".(length($tee) % 8)."\n"; 0

#print ord(1)." FF: ".&hex2int(1)."\n";

#my $Stee=&bin2cn($tee);
#print "TT: $Stee\n";

my $ods= "E4B896E7958CEFBC8CE4BDA0E5A5BDE38082";
my $des=&hex2bin($ods);
my $Stea=&bin2cn($des);
print "TT: $Stea\n";