line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Webqq::Encryption::TEA; |
2
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
21
|
|
3
|
1
|
|
|
1
|
|
4
|
use Carp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
43
|
|
4
|
1
|
|
|
1
|
|
457
|
use MIME::Base64 (); |
|
1
|
|
|
|
|
623
|
|
|
1
|
|
|
|
|
29
|
|
5
|
1
|
|
|
1
|
|
365
|
use Webqq::Encryption::TEA::Perl; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
38
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
BEGIN{ |
8
|
1
|
|
|
1
|
|
2
|
eval{require JE;}; |
|
1
|
|
|
|
|
273
|
|
9
|
1
|
50
|
|
|
|
578
|
$Webqq::Encryption::TEA::has_je = 1 unless $@; |
10
|
|
|
|
|
|
|
} |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub encrypt_js{ |
14
|
0
|
|
|
0
|
0
|
|
my ($key,$data) = @_; |
15
|
0
|
|
|
|
|
|
my $je = _load_je(); |
16
|
0
|
|
|
|
|
|
my $p = $je->eval(qq# |
17
|
|
|
|
|
|
|
var tea = TEA(); |
18
|
|
|
|
|
|
|
tea.initkey('$key'); |
19
|
|
|
|
|
|
|
var r = tea.encrypt2('$data'); |
20
|
|
|
|
|
|
|
tea.initkey(''); |
21
|
|
|
|
|
|
|
return(r); |
22
|
|
|
|
|
|
|
#); |
23
|
0
|
0
|
0
|
|
|
|
if($p and !$@){ |
24
|
0
|
|
|
|
|
|
return $p; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
else{ |
27
|
0
|
|
|
|
|
|
croak "Webqq::Encryption::TEA error: $@\n"; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
sub decrypt_js{ |
31
|
0
|
|
|
0
|
0
|
|
my ($key,$data) = @_; |
32
|
0
|
|
|
|
|
|
my $je = _load_je(); |
33
|
0
|
|
|
|
|
|
my $p = $je->eval(qq# |
34
|
|
|
|
|
|
|
var tea = TEA(); |
35
|
|
|
|
|
|
|
tea.initkey('$key'); |
36
|
|
|
|
|
|
|
var r = tea.decrypt('$data'); |
37
|
|
|
|
|
|
|
tea.initkey(''); |
38
|
|
|
|
|
|
|
return(r); |
39
|
|
|
|
|
|
|
#); |
40
|
0
|
0
|
0
|
|
|
|
if($p and !$@){ |
41
|
0
|
|
|
|
|
|
return $p; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
else{ |
44
|
0
|
|
|
|
|
|
croak "Webqq::Encryption::TEA error: $@\n"; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub strToHex{ |
49
|
0
|
|
|
0
|
0
|
|
my $str = shift; |
50
|
0
|
|
|
|
|
|
my $return = ""; |
51
|
0
|
|
|
|
|
|
for(split //,$str){$return .= sprintf "%02x",ord($_)}; |
|
0
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
return $return; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub hexToStr{ |
56
|
0
|
|
|
0
|
0
|
|
return pack "H*",lc shift; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
sub _load_je{ |
59
|
0
|
|
|
0
|
|
|
my $je; |
60
|
0
|
0
|
|
|
|
|
croak "The JE module is not found, You may install it first\n" unless $Webqq::Encryption::TEA::has_je; |
61
|
0
|
0
|
|
|
|
|
if(defined $Webqq::Encryption::TEA::_je ){ |
62
|
0
|
|
|
|
|
|
$je = $Webqq::Encryption::TEA::_je ; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
else{ |
65
|
0
|
|
|
|
|
|
my $javascript; |
66
|
0
|
0
|
|
|
|
|
if(defined $Webqq::Encryption::TEA::_javascript){ |
67
|
0
|
|
|
|
|
|
$javascript = $Webqq::Encryption::TEA::_javascript; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
else{ |
70
|
0
|
|
|
|
|
|
local $/ = undef; |
71
|
0
|
|
|
|
|
|
$javascript = ; |
72
|
0
|
|
|
|
|
|
$Webqq::Encryption::TEA::_javascript = $javascript; |
73
|
0
|
|
|
|
|
|
close DATA; |
74
|
|
|
|
|
|
|
} |
75
|
0
|
|
|
|
|
|
$je = JE->new; |
76
|
0
|
|
|
|
|
|
$je->eval($javascript); |
77
|
0
|
0
|
|
|
|
|
croak "Webqq::Encryption::TEA load javascript error: $@\n" if $@; |
78
|
0
|
|
|
|
|
|
$Webqq::Encryption::TEA::_je = $je; |
79
|
|
|
|
|
|
|
} |
80
|
0
|
|
|
|
|
|
return $je; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
sub encrypt { |
83
|
0
|
|
|
0
|
0
|
|
my ($key,$data) = @_; |
84
|
0
|
|
|
|
|
|
my $p = Webqq::Encryption::TEA::Perl::encrypt(hexToStr($data),hexToStr($key)); |
85
|
0
|
|
|
|
|
|
return lc join "",unpack "H*",$p; |
86
|
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
my $je = _load_je(); |
88
|
0
|
|
|
|
|
|
$p = $je->eval(qq# |
89
|
|
|
|
|
|
|
var tea = TEA(); |
90
|
|
|
|
|
|
|
tea.initkey('$key'); |
91
|
|
|
|
|
|
|
var r = tea.encrypt('$data'); |
92
|
|
|
|
|
|
|
tea.initkey(''); |
93
|
|
|
|
|
|
|
return(r); |
94
|
|
|
|
|
|
|
#); |
95
|
0
|
0
|
0
|
|
|
|
if($p and !$@){ |
96
|
0
|
|
|
|
|
|
return $p; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
else{ |
99
|
0
|
|
|
|
|
|
croak "Webqq::Encryption::TEA error: $@\n"; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
1; |
104
|
|
|
|
|
|
|
__DATA__ |