我有这个脚本,工作正常:
#!/usr/bin/perl
$key = pack("H*","3cb37efae7f4f376ebbd76cd");
$str = "&4\=80CHB'";
$dec = decode($str);
print "Decoded string value: $dec\n";
sub decode{ #Sub to decode
@subvar=@_;
my $sqlstr = $subvar[0];
$cipher = unpack("u", $sqlstr);
$plain = $cipher^$key;
return substr($plain, 0, length($cipher));
}
如果我改变它以从STDIN获取$ str变量,它会弄乱所有结果:
#!/usr/bin/perl
$key = pack("H*","3cb37efae7f4f376ebbd76cd");
print "Enter string to decode: ";
$str=<STDIN>;chomp $str;
$dec = decode($str);
print "Decoded string value: $dec\n";
sub decode{ #Sub to decode
@subvar=@_;
my $sqlstr = $subvar[0];
$cipher = unpack("u", $sqlstr);
$plain = $cipher^$key;
return substr($plain, 0, length($cipher));
}
第一个脚本没问题,结果是:
解码后的字符串值:mentos
第二个脚本不好:
解码后的字符串值:ot&amp;¸ÝÖóvë½vÍ
知道我做错了什么吗?谢谢!
答案 0 :(得分:3)
原始代码有
$str = "&4\=80CHB'";
由于某种原因包含转义的等号。它与
相同$str = "&4=80CHB'";
因此您需要在修改过的代码中输入&4=80CHB'
。