1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
| ---------------------- bit utils
| bit={data32={}}
| for i=1,32 do
| bit.data32[i]=2^(32-i)
| end
|
| function bit.d2b(arg)
| local tr={}
| for i=1,32 do
| if arg >= bit.data32[i] then
| tr[i]=1
| arg=arg-bit.data32[i]
| else
| tr[i]=0
| end
| end
| return tr
| end --bit:d2b
|
| function bit.b2d(arg)
| local nr=0
| for i=1,32 do
| if arg[i] ==1 then
| nr=nr+2^(32-i)
| end
| end
| return nr
| end --bit:b2d
|
| function bit._xor(a,b)
| local op1=bit.d2b(a)
| local op2=bit.d2b(b)
| local r={}
|
| for i=1,32 do
| if op1[i]==op2[i] then
| r[i]=0
| else
| r[i]=1
| end
| end
| return bit.b2d(r)
| end --bit:xor
|
| function bit._and(a,b)
| local op1=bit.d2b(a)
| local op2=bit.d2b(b)
| local r={}
|
| for i=1,32 do
| if op1[i]==1 and op2[i]==1 then
| r[i]=1
| else
| r[i]=0
| end
| end
| return bit.b2d(r)
|
| end --bit:_and
|
| function bit._or(a,b)
| local op1=bit.d2b(a)
| local op2=bit.d2b(b)
| local r={}
|
| for i=1,32 do
| if op1[i]==1 or op2[i]==1 then
| r[i]=1
| else
| r[i]=0
| end
| end
| return bit.b2d(r)
| end --bit:_or
|
| function bit._not(a)
| local op1=bit.d2b(a)
| local r={}
|
| for i=1,32 do
| if op1[i]==1 then
| r[i]=0
| else
| r[i]=1
| end
| end
| return bit.b2d(r)
| end --bit:_not
|
| function bit._rshift(a,n)
| local op1=bit.d2b(a)
| local r=bit.d2b(0)
|
| if n < 32 and n > 0 then
| for i=1,n do
| for i=31,1,-1 do
| op1[i+1]=op1[i]
| end
| op1[1]=0
| end
| r=op1
| end
| return bit.b2d(r)
| end --bit:_rshift
|
| function bit._lshift(a,n)
| local op1=bit.d2b(a)
| local r=bit.d2b(0)
|
| if n < 32 and n > 0 then
| for i=1,n do
| for i=1,31 do
| op1[i]=op1[i+1]
| end
| op1[32]=0
| end
| r=op1
| end
| return bit.b2d(r)
| end --bit:_lshift
|
| function bit.print(ta)
| local sr=""
| for i=1,32 do
| sr=sr..ta[i]
| end
| print(sr)
| end
|
|
|
|
| -------------------------------- core
| y_key = {1206625642, 1092691841, 3888211297, 1403752353}
| t_key = {768304513, 3648063403, 1200350539, 1135324489}
| y_live_key = {2380375339, 3372821835, 757854091, 3417384251}
| t_live_key = {1307283402, 3415975219, 130748267, 1094264761}
|
| function getConfused(flag)
| local ftr = math.log10(1000);
| local ftr2 = math.log10(100);
| local key = {};
| if flag==0 then
| key = y_key;
| elseif flag == 1 then
| key = t_key;
| elseif flag == 2 then
| key = y_live_key;
| elseif flag == 3 then
| key = t_live_key;
| end
| local a = math.max(key[1], ftr);
| local b = math.min(key[2], ftr2);
| local c = math.max(key[3], ftr);
| local d = math.min(key[4], ftr2);
| return a, b, c, d;
| end
|
|
| function doDec(ciphertxt, len, flag)
| dc = luajava.newInstance("com.decapi.Decryptions");
| local L, l, R, r = getConfused(flag);
| ret = dc:AESDec(ciphertxt, len, math.btan2(L, l, R, r));
| return ret;
| end
|
| function doEnc(plaintxt, flag)
| ec = luajava.newInstance("com.decapi.Decryptions");
| local L, l, R, r = getConfused(flag);
| ret = ec:AESEnc(plaintxt, math.btan2(L, l, R, r));
| return ret;
| end
|
|