【发布时间】:2013-02-06 18:06:31
【问题描述】:
我在左边有以下字符串,右边是编码值:
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
【问题讨论】:
-
数据是如何编码的?
-
一些Java,我从管理面板手动编码。
-
编码算法有记录吗?你能查看它的来源吗?
-
这里是 java 和一个旧的讨论:stackoverflow.com/questions/10085074/…
-
混合了脚本。无论如何,我正在暴力破解 HEX,我已经可以使用
3cb37efae7f4f376ebbd76cdfce7391e9e键解码 17 个字符长的字符串。
标签: perl encoding xor uuencode