···11+--[[
22+ String XOR Encryption By Jericho
33+ Version: 1.0.0
44+ Source available at: https://github.com/Jericho1060/DualUniverse/blob/master/CryptString/CryptString.lua
55+]]
66+77+CryptString = {
88+ __index = {
99+ keyToDataLen = function (self, key, len)
1010+ if #key >= len then
1111+ return key:sub(1, len)
1212+ end
1313+ local result = ""
1414+ for i = 1, math.floor(len / #key) do
1515+ result = result .. key
1616+ end
1717+ local leftLen = len % #key
1818+ if leftLen > 0 then
1919+ result = result .. key:sub(1, leftLen)
2020+ end
2121+ return result
2222+ end,
2323+ xor = function (self, num1, num2)
2424+ local tmp1 = num1
2525+ local tmp2 = num2
2626+ local str = ""
2727+ while tmp1 > 0 or tmp2 > 0 do
2828+ local digit1 = tmp1 % 2
2929+ local digit2 = tmp2 % 2
3030+ if digit1 == digit2 then
3131+ str = "0" .. str
3232+ else
3333+ str = "1" .. str
3434+ end
3535+ tmp1 = math.floor(tmp1 / 2)
3636+ tmp2 = math.floor(tmp2 / 2)
3737+ end
3838+ return tonumber(str, 2)
3939+ end,
4040+ crypt = function(self, data, key)
4141+ key = self:keyToDataLen(key, #data)
4242+ local result = ''
4343+ for i = 1, #data do
4444+ result = result .. string.char(self:xor(data:sub(i, i):byte(), key:sub(i, i):byte()))
4545+ end
4646+ return result
4747+ end
4848+ }
4949+}
+6
CryptString/CryptString.min.lua
···11+--[[
22+ String XOR Encryption By Jericho
33+ Version: 1.0.0
44+ Source available at: https://github.com/Jericho1060/DualUniverse/blob/master/CryptString/CryptString.lua
55+]]
66+CryptString={__index={keyToDataLen=function(self,a,b)if#a>=b then return a:sub(1,b)end;local c=""for d=1,math.floor(b/#a)do c=c..a end;local e=b%#a;if e>0 then c=c..a:sub(1,e)end;return c end,xor=function(self,f,g)local h=f;local i=g;local j=""while h>0 or i>0 do local k=h%2;local l=i%2;if k==l then j="0"..j else j="1"..j end;h=math.floor(h/2)i=math.floor(i/2)end;return tonumber(j,2)end,crypt=function(self,m,a)a=self:keyToDataLen(a,#m)local c=''for d=1,#m do c=c..string.char(self:xor(m:sub(d,d):byte(),a:sub(d,d):byte()))end;return c end}}