Skip to content
This repository has been archived by the owner on Dec 1, 2024. It is now read-only.

Commit

Permalink
version 1.1-1
Browse files Browse the repository at this point in the history
  • Loading branch information
ttwizz authored Apr 14, 2024
1 parent 174612b commit 40573e1
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/pixcrypt.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
--[[
pixcrypt
Key-based Encryption & Decryption Library
ttwizz.su/pix
Author: ttwiz_z (ttwizz)
License: MIT
GitHub: https://github.com/ttwizz/pixcrypt
]]


local pixcrypt = {}


function pixcrypt:Encrypt(Key, String)
assert(type(Key) == "string", "Argument 1 (Key) must be a string")
assert(type(String) == "string", "Argument 2 (String) must be a string")

local Summand = #Key + math.pi * 4.3579
local Result = ""

for Character in string.gmatch(Key, ".") do
Summand = Summand + string.byte(Character) / 1.8602
end
for Character in string.gmatch(String, ".") do
Result = Result .. string.byte(Character) / 2.1748 + Summand .. "xip"
end

return string.gsub(string.reverse(string.sub(Result, 1, -4)), "%.", "$")
end

function pixcrypt:Decrypt(Key, String)
assert(type(Key) == "string", "Argument 1 (Key) must be a string")
assert(type(String) == "string", "Argument 2 (String) must be a string")

local Summand = #Key + math.pi * 4.3579
local Result = ""

for Character in string.gmatch(Key, ".") do
Summand = Summand + string.byte(Character) / 1.8602
end
for Character in string.gmatch(string.gsub(string.reverse(String), "%$", "."), "([^xip]+)") do
Result = Result .. string.char(math.floor((Character - Summand) * 2.1748 + 0.5))
end

return Result
end


return pixcrypt

0 comments on commit 40573e1

Please sign in to comment.