我在左边有以下字符串,右边有编码值:
123456789012 ,\#8%-SM+"Q$[2C4?_\n
1234567890123 -\#8%-SM+"Q$[2C4?_SP \n
12345678901234 .\#8%-SM+"Q$[2C4?_S], \n
123456789012345 /\#8%-SM+"Q$[2C4?_S],,\n
1234567890123456 0\#8%-SM+"Q$[2C4?_S],,* \n
12345678901234567 1\#8%-SM+"Q$[2C4?_S],,**D \n
123456789012345678 2\#8%-SM+"Q$[2C4?_S],,**GA\n
1234567890123456789 3\#8%-SM+"Q$[2C4?_S],,**GA]P \n
12345678901234567890 4\#8%-SM+"Q$[2C4?_S],,**GA]]0 \n
123456789012345678901 5\#8%-SM+"Q$[2C4?_S],,**GA]]3^\n
1234567890123456789012 6\#8%-SM+"Q$[2C4?_S],,**GA]]3^_ \n
12345678901234567890123 7\#8%-SM+"Q$[2C4?_S],,**GA]]3^_(< \n
123456789012345678901234 8\#8%-SM+"Q$[2C4?_S],,**GA]]3^_(>'\n
我试图复制解码过程(uudecode -> XOR with key),如下所示:
#!/usr/bin/perl
$key = pack("H*","3cb37efae7f4f376ebbd76cdfc");
print "Enter string to decode: ";
$str=<STDIN>;chomp $str; $str =~s/\\(.)/$1/g;
$dec = decode($str);
print "Decoded string value: $dec\n";
sub decode{ #Sub to decode
my ($sqlstr) = @_;
$cipher = unpack("u", $sqlstr);
$plain = $cipher^$key;
return substr($plain, 0, length($cipher));
}
一切正常,直到我得到一个由 13 个字符组成的字符串:
# perl d.pl
Enter string to decode: -\#8%-SM+"Q$[2C4?_SP \n
Decoded string value: 1234567890123
# perl d.pl
Enter string to decode: .\#8%-SM+"Q$[2C4?_S], \n
Decoded string value: 1234567890123Ó
关于如何解码所有编码数据的任何想法?谢谢!
好的,我自己想出了 HEX 中的密钥。此密钥3cb37efae7f4f376ebbd76cdfce7391e9ed9cee4cfceb4b3
解码我所有的加密数据。
解决方案,由于ikegami,代码更简洁:
#!/usr/bin/perl
use strict;
use warnings;
sub deliteral {
my ($s) = @_;
$s =~ s/\\n/\n/g;
die "Unrecognised escape \\$1\n"
if $s =~ /(?<!\\)(?:\\{2})*\\([a-zA-Z0-9])/;
$s =~ s/\\(.)/$1/sg;
return $s;
}
sub uudecode {
return unpack 'u', $_[0];
}
sub decode {
my ($key, $cipher) = @_;
return substr($cipher^$key, 0, length($cipher));
}
my $key = pack('H*', '3cb37efae7f4f376ebbd76cdfce7391e9ed9cee4cfceb4b3');
print "Enter string to decode: ";
chomp( my $coded = <STDIN> );
my $cipher = uudecode(deliteral($coded));
my $plain = decode($key, $cipher);
print("Plain text: $plain\n");
输出:
$ perl deXOR.pl
Enter string to decode: ,\#8%-SM+"Q$[2C4?_\n
Plain text: 123456789012
$ perl deXOR.pl
Enter string to decode: 8\#8%-SM+"Q$[2C4?_S],,**GA]]3^_(>'\n
Plain text: 123456789012345678901234