perl base64解码

前端之家收集整理的这篇文章主要介绍了perl base64解码前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

看phrack的时候,作者的代码有时不是以plain text的格式粘贴出来,有时使用了base64的编码,有时使用的uuencode格式的编码。

要识别base64还是uuencode编码可以看文件的第一行,如果明确了base64的话,那么就是base64编码,否则很有可能就是uuencode。

于是写了一个小脚本用来把base64/uuencode转换成tar.gz(大多数情况下都是这种格式)的。

使用方法

文件粘贴到记事本中保存之。然后运行脚本。

如果是UUEncode的编码, 则begin和end也要保存。

然后运行

perl decode.pl -s source.txt -d dest.txt -c base64

perl  decode.pl -s a.txt  -c UU


===========================================================================================

decode.pl

===========================================================================================

#!/usr/bin/perl -w use strict; use warnings; use MIME::Base64; use Convert::UU qw(uudecode); use Getopt::Long; my $srcfile; my $dstfile; my $help; my $encode; GetOptions(         'h|help'        => \$help,        's=s'           => \$srcfile,        'd=s'           => \$dstfile,        'c=s'           => \$encode); sub help{         print <<_EOT_; 'perl $0 -s source.txt -d dest.txt -c base64' 'perl $0 -s source.txt -c UU' only decode base64 or UU when decoding base64,you should specify the dst file name _EOT_         exit; } help() if $help; help() unless $srcfile; help() unless ($encode eq "base64") or ($encode eq "UU"); print "$srcfile doesn't exist\n" unless -e $srcfile; sub main_base64{         my ($src,$dst) = @_;         my $in;         my $out;         my $string;         my $result;         help() unless $dst;         open $in,$src;         open $out,">",$dst;         while(<$in>){                 chomp;                 $string = $string.$_;         } #       if($enc eq "base64"){         $result = decode_base64($string); #       }elsif($enc eq "UU"){ #               $result = uudecode($string,"vlc_lulz_v0.1.tar.gz",644 ); #       }         print $out $result;         close($in);         close($out);         print "Done\n";         exit; } sub main_uu{         my ($src,$dst) = @_;         my $in;         my $out;         open $in,$src;         my($string,$filename,$mode) = uudecode($in);         open $out,$filename;         print $out $string;         close($in);         close($out);         print "Done\n";         exit; } main_base64($srcfile,$dstfile)if $encode eq "base64"; main_uu($srcfile,$dstfile) if $encode eq "UU";

猜你在找的Perl相关文章