ObscuredValue.lua
3.86 KB
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
local cryptoKey = 0x020207070202
local delta = 8
local mt = {}
function mt.__add(a, b)
local ta = type(a)
local tb = type(b)
if ta == "table" and tb == "table" then
return Obscured(a.Decrypt() + b.Decrypt())
end
if ta == "number" then
return Obscured(a + b.Decrypt())
end
if tb == "number" then
return Obscured(a.Decrypt() + b)
end
error("add wrong")
end
function mt.__sub(a, b)
local ta = type(a)
local tb = type(b)
if ta == "table" and tb == "table" then
return Obscured(a.Decrypt() - b.Decrypt())
end
if ta == "number" then
return Obscured(a - b.Decrypt())
end
if tb == "number" then
return Obscured(a.Decrypt() - b)
end
error("sub wrong")
end
function mt.__mul(a, b)
local ta = type(a)
local tb = type(b)
if ta == "table" and tb == "table" then
return Obscured(a.Decrypt() * b.Decrypt())
end
if ta == "number" then
return Obscured(a * b.Decrypt())
end
if tb == "number" then
return Obscured(a.Decrypt() * b)
end
error("sub wrong")
end
function mt.__div(a, b)
local ta = type(a)
local tb = type(b)
if ta == "table" and tb == "table" then
return Obscured(a.Decrypt() / b.Decrypt())
end
if ta == "number" then
return Obscured(a / b.Decrypt())
end
if tb == "number" then
return Obscured(a.Decrypt() / b)
end
error("sub wrong")
end
function mt.__mod(a, b)
local ta = type(a)
local tb = type(b)
if ta == "table" and tb == "table" then
return Obscured(a.Decrypt() % b.Decrypt())
end
if ta == "number" then
return Obscured(a % b.Decrypt())
end
if tb == "number" then
return Obscured(a.Decrypt() % b)
end
error("sub wrong")
end
function mt.__unm(a)
return Obscured(-a.Decrypt())
end
function mt.__len(a)
return #a.Decrypt()
end
function mt.__lt(a, b)
return a.Decrypt() < b.Decrypt()
end
function mt.__le(a, b)
return a.Decrypt() <= b.Decrypt()
end
function mt.__eq(a, b)
return a.Decrypt() == b.Decrypt()
end
function mt.__call(t)
return t.Decrypt()
end
function mt.__newindex(t,_,v)
t.SetVaule(v)
end
function mt.__index(t)
return t.Decrypt()
end
local function Obscured(value)
local hiddenValue = value
local currentKey = cryptoKey
local dataName = type(value)
local o = {}
function o.Encrypt(value, key)
key = key or currentKey
if type(value) == "number" then
value = tostring(value)
end
hiddenValue = {}
for i = 1, #value do
hiddenValue[i] = string.byte(value, i)
hiddenValue[i] = bit.bxor(hiddenValue[i], key)
if hiddenValue[i] % 2 == 1 then
hiddenValue[i] = 2*hiddenValue[i] + delta + 7
else
hiddenValue[i] = 2*hiddenValue[i] - delta
end
end
end
function o.Decrypt(key)
key = key or currentKey
local d = ""
for i,v in ipairs(hiddenValue) do
if v % 2 == 1 then
v = v - delta - 7
else
v = v + delta
end
v = v / 2
v = bit.bxor(v, key)
d = d .. string.char(v)
end
if dataName == "number" then
d = tonumber(d)
end
return d
end
function o.SetNewCryptoKey(newKey)
cryptoKey = newKey
o.ApplyNewCryptoKey()
end
function o.ApplyNewCryptoKey()
if currentKey ~= cryptoKey then
o.Encrypt(Decrypt(), cryptoKey)
currentKey = cryptoKey
end
end
function o.SetVaule(value)
hiddenValue = value
dataName = type(value)
o.Encrypt(value)
end
o.Encrypt(value)
setmetatable(o,mt)
return o
end
return Obscured