From 40573e1ca77e4a5659f0d7e8700915c327d83db0 Mon Sep 17 00:00:00 2001 From: ttwiz_z Date: Sun, 14 Apr 2024 10:30:35 +0300 Subject: [PATCH] version 1.1-1 --- src/pixcrypt.lua | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/pixcrypt.lua diff --git a/src/pixcrypt.lua b/src/pixcrypt.lua new file mode 100644 index 0000000..3b4bbc8 --- /dev/null +++ b/src/pixcrypt.lua @@ -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