So I was looking into encryption for a server based program I was making. The program has user sending passwords over rednet, so I needed an encryption. Unfortunately, the only one I found, was this one by Malte. But that one was buggy and cracked. But looking at the reason it was buggy, it gave me an idea. So I went ahead and created this. It's sort of secure, so long as nobody else knows your key. It's simple code, yet complex encryption.
--Syntax:
encrypt(string, key)
decrypt(string, key)
-- Pretty self explanatory. Examples:
x = "This is an example string. :aFj(-$%;!"
str = encrypt(x, "4bG29x")
print(str)
--Output:
-80-118-98-103-128-141-105-147-90-98-128-137-110-111-102-100-103-137-123-129-109-102-100-146-93-148-126-135-92-112-96-151-134-128-139
-------------------------------------------------------------
newStr = decrypt(str, "4bG29x")
print(newStr)
--Output:
This is an example string. :aFj(-$%;!
---------------------------------------------------------------
newStr = decrypt(str, "abc123")
print(newStr)
--Output:
Z p+~~y~h%~~44t#!~&!1!$~m~%~ /p~;~~
----------------------------------------------------------------
newStr = decrypt(str, "4bG29y")
print(newStr)
--Output:
This hs am dxampld strimg. :aEj($%!
So basically, just keep your key complex. These are currently the supported characters:
charValues = {
"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P",
"Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e",
"f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t",
"u", "v", "w", "x", "y", "z", "1", "2", "3", "4", "5", "6", "7", "8", "9",
"0", " ", ".", ",", ")", "(", "*", "&", "%", "$", "#", "@", "!", "+", "=", ":",
";", "\"", "'", "?", "/", "~", "-"
}
You can easily add more or remove some by simply adding to or removing from this table at the top of the code. Those characters listed are the only ones you can use in text or keys; those are the only ones that this algorithm understands. Again, you could add more if you need to.Pastebin:
http://pastebin.com/NkeDTRMB
pastebin get NkeDTRMB utfe
This also works in pure Lua; it uses no CCApi. Let me know if you find any bugs or what not. And, as always, enjoy!