Skip to content

Commit 95e0ac8

Browse files
committed
Change bitwise xor functions. Fix gg.prompt array index.
1 parent 0a88c1d commit 95e0ac8

File tree

3 files changed

+40
-32
lines changed

3 files changed

+40
-32
lines changed

data/templates.lua

+17-13
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,23 @@
22
-- key = gg.prompt({"请输入密码:"}, {""}, {"text"})
33
key = "把这里替换成密码"
44
-- load
5-
local main = loadstring((function (bytes, key)
5+
local main = loadstring((function (bytes, key_)
66
-- http://lua-users.org/wiki/BitUtils
77
function bxor(a, b)
8-
local r = 0
9-
for i = 0, 31 do
10-
local x = a / 2 + b / 2
11-
if x ~= math.floor(x) then
12-
r = r + 2 ^ i
13-
end
8+
local XOR_l =
9+
{
10+
{0, 1},
11+
{1, 0},
12+
}
13+
local pow = 1
14+
local c = 0
15+
while a > 0 or b > 0 do
16+
c = c + (XOR_l[(a % 2) + 1][(b % 2) + 1] * pow)
1417
a = math.floor(a / 2)
1518
b = math.floor(b / 2)
19+
pow = pow * 2
1620
end
17-
return r
21+
return c
1822
end
1923

2024
local getDataBytes = function (bytes)
@@ -29,16 +33,16 @@ local main = loadstring((function (bytes, key)
2933
return result
3034
end
3135

32-
local decode = function (bytes, key)
33-
if #key <= 0 then
36+
local decode = function (bytes, key_)
37+
if #key_ <= 0 then
3438
return {}
3539
end
3640
local i = 1
3741
local j = 1
3842
for i = 1, #bytes do
39-
bytes[i] = bxor(bytes[i], string.byte(key, j))
43+
bytes[i] = bxor(bytes[i], string.byte(key_, j))
4044
j = j + 1
41-
if j > #key then
45+
if j > #key_ then
4246
j = 1
4347
end
4448
end
@@ -53,7 +57,7 @@ local main = loadstring((function (bytes, key)
5357
return result
5458
end
5559

56-
return bytesToString(decode(getDataBytes(bytes), key))
60+
return bytesToString(decode(getDataBytes(bytes), key_))
5761
end)({
5862
-- data
5963
}, key))

0 commit comments

Comments
 (0)