This repository has been archived by the owner on Dec 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |