Encryption: Caesar Cipher |
![]() ![]() « Citoyen » 1464513960000
| 0 | ||
--[[Note: The original codebase is not mine, please refer the link below]]-- --[[Caesar Cipher example to be integrated with Module API.]]-- --[[Logic of cipher taken from - http://www.rosettacode.org/wiki/Caesar_cipher#Lua]]-- --[[As a supporter of free software, and don't wanna reinvent the wheel for no reason, I choose to take an existing codebase and integrate it with simple Module API]]-- --[[Target: lua feature (tfm). For luaj (java), and luajit(just-in-time) compiler, running on nginx currently]]-- --[[Modified by: Pydlua, credits to Rosettacode.org]]-- -- TO USE: !messagetoencrypt -- Change the key to any number (max: 25) (default is 7) local function encrypt(text, key) return text:gsub("%a", function(t) local base = (t:lower() == t and string.byte('a') or string.byte('A')) local r = t:byte() - base r = r + key r = r%26 -- works correctly even if r is negative r = r + base return string.char(r) end) end local function decrypt(text, key) return encrypt(text, -key) end caesar = { encrypt = encrypt, decrypt = decrypt, } -- change the addTextArea target player, to send to specific player -- By default is nil that is all player available in the room --[[ Example to add specific player: newPlayer="your_friend) ui.addTextArea(1,"Encrypted text: " .. encrypted,newPlayer,500,180,500,200,0x324650,0x212F36,0.8,true) ui.addPopup(1,0,decrypted,newPlayer,-160,180,500,true) by adding this, this will make your friend also see the window ]]-- key=7 target="Pydlua" function eventChatCommand(target, text) local encrypted = caesar.encrypt(text, key) local decrypted = caesar.decrypt(encrypted, key) print("Original message: "..text) print("Encrypted text: "..encrypted) print("Decrypted message: "..decrypted) ui.addTextArea(1,"Encrypted text: " .. encrypted,nil,500,180,500,200,0x324650,0x212F36,0.8,true) ui.addPopup(1,0,"Decrypted text: "..decrypted,nil,-160,180,500,true) end Yeah, another probably useless code for tfm player, but also possibly useful for whoever wanted to learn encryption with lua via tfm lua feature. I know, not everyone here got access to lua interpreter in their PC (natively) plus most player use Windows. So I found this binary (exe) for Windows to install lua interpreter and dependencies - https://code.google.com/archive/p/luaforwindows/downloads Advantage to use lua on your native platform -
Why I'm mentioning all of the list above? It's good to know a bit more for who don't. Note: I am not really familiar with Windows operating system, nor Module API 801, nor Lua language. It's just curiosity. I'm sorry if the facts are not accurate, or just plainly wrong. ps: my english, shiver me timbers. |
![]() ![]() « Citoyen » 1464514380000
| 0 | ||
Note: on line 37, there is a type error -> "your_friend) Change it to "your_friend" although the script is running fine even the type error is there hmm :\ |
0 | ||
this is pretty darn cool could be an extremely complicated way of adding a password |
![]() ![]() « Citoyen » 1464941100000
| 0 | ||
btw, sometimes ciphers are easy if u get used to em :3 |