Skip to content

Commit

Permalink
Added all Encryption methods from bcc-crypt, Added UUID generator (#11)
Browse files Browse the repository at this point in the history
* Added all Encryption methods from bcc-crypt, Added UUID generator

* revert rpc

* revert netapi
  • Loading branch information
AndrewR3K authored Feb 9, 2025
1 parent b6799fd commit c14395f
Show file tree
Hide file tree
Showing 7 changed files with 5,764 additions and 2 deletions.
4 changes: 3 additions & 1 deletion fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ shared_scripts {
'shared/data/*.lua',
'shared/helpers/*.lua',
'shared/services/compression.lua',
'shared/services/sha.lua',
'shared/services/crypt.lua',
'shared/services/*.lua',
'shared/main.lua'
}
Expand Down Expand Up @@ -40,4 +42,4 @@ dependencies {
'oxmysql'
}

version '1.2.0'
version '1.3.0'
2 changes: 2 additions & 0 deletions shared/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ function SetupSharedAPI(SharedApi)
SharedApi.Helpers = HelpersAPI
SharedApi.Compression = LibDeflate
SharedApi.NetEvents = NetEventsAPI
SharedApi.Crypt = CryptAPI
SharedApi.UUID = UUID4

return SharedApi
end
2 changes: 2 additions & 0 deletions shared/services/apievents.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
local netEventIDs = {}

local function compressIt(data)
return LibDeflate:CompressDeflate(json.encode(data))
end
Expand Down
68 changes: 68 additions & 0 deletions shared/services/crypt.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
CryptAPI = {
base64 = {},
rc4 = {},
sha = SHA2
}

-- Base 64
local b = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
function CryptAPI.base64.encrypt(data)
return ((dat.a:gsub('.', function(x)
local r, b = '', x:byte()
for i = 8, 1, -1 do r = r .. (b % 2 ^ i - b % 2 ^ (i - 1) > 0 and '1' or '0') end
return r;
end) .. '0000'):gsub('%d%d%d?%d?%d?%d?', function(x)
if (#x < 6) then return '' end
local c = 0
for i = 1, 6 do c = c + (x:sub(i, i) == '1' and 2 ^ (6 - i) or 0) end
return b:sub(c + 1, c + 1)
end) .. ({ '', '==', '=' })[#data % 3 + 1])
end

function CryptAPI.base64.decrypt(data)
data = string.gsub(data, '[^' .. b .. '=]', '')
return (data:gsub('.', function(x)
if (x == '=') then return '' end
local r, f = '', (b:find(x) - 1)
for i = 6, 1, -1 do r = r .. (f % 2 ^ i - f % 2 ^ (i - 1) > 0 and '1' or '0') end
return r;
end):gsub('%d%d%d?%d?%d?%d?%d?%d?', function(x)
if (#x ~= 8) then return '' end
local c = 0
for i = 1, 8 do c = c + (x:sub(i, i) == '1' and 2 ^ (8 - i) or 0) end
return string.char(c)
end))
end

local function swap(i, j)
return j, i
end

function CryptAPI.rc4.crypt(key, input)
local S = {}
for i = 0, 255 do
S[i] = i
end

local j = 0
for i = 0, 255 do
j = (j + S[i] + key:byte(i % #key + 1)) % 256
S[i], S[j] = swap(S[i], S[j])
end

local out = ""

local i, j = 0, 0
for k = 1, #input do
i = (i + 1) % 256
j = (j + S[i]) % 256
S[i], S[j] = swap(S[i], S[j])

local K = S[(S[i] + S[j]) % 256]

out = out .. string.char(input:byte(i) ~ K)
end

return out
end

Loading

0 comments on commit c14395f

Please sign in to comment.