×

Langue

Fermer
Atelier 801
  • Forums
  • Dev Tracker
  • Connexion
    • English Français
      Português do Brasil Español
      Türkçe Polski
      Magyar Română
      العربية Skandinavisk
      Nederlands Deutsch
      Bahasa Indonesia Русский
      中文 Filipino
      Lietuvių kalba 日本語
      Suomi עברית
      Italiano Česky
      Hrvatski Slovensky
      Български Latviešu
      Estonian
  • Langue
  • Forums
  • /
  • Transformice
  • /
  • Modules
  • /
  • Encryption: Caesar Cipher
Encryption: Caesar Cipher
Pydlua
« Citoyen »
1464513960000
    • Pydlua#0000
    • Profil
    • Derniers messages
#1
  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 -
  • It comes with default non-stripped modules/depends, Module API (for tfm) is stripped for some reason(I believe for security to avoid malicous code injection through the default Lua API
  • You can program Lua offline. No need internet connection for this.
  • You can program Lua to embed with other program, such as in the ansychronous Nginx server(like this game, I believe), and even vice versa with C.
  • Use to script your system shell either Powershell, or Bash/sh/zsh/tcsh/etc through os.execute()[*/]


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.
Pydlua
« Citoyen »
1464514380000
    • Pydlua#0000
    • Profil
    • Derniers messages
#2
  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 :\
Onkei
« Citoyen »
1464516600000
    • Onkei#0000
    • Profil
    • Derniers messages
    • Tribu
#3
  0
this is pretty darn cool

could be an extremely complicated way of adding a password
Ratrollerz
« Citoyen »
1464941100000
    • Ratrollerz#0000
    • Profil
    • Derniers messages
    • Tribu
#4
  0
btw, sometimes ciphers are easy if u get used to em :3
  • Forums
  • /
  • Transformice
  • /
  • Modules
  • /
  • Encryption: Caesar Cipher
© Atelier801 2018

Equipe Conditions Générales d'Utilisation Politique de Confidentialité Contact

Version 1.27