Encryption in IRC added.
This commit is contained in:
parent
77d8d0509b
commit
1db8357169
52
crypt.lua
Normal file
52
crypt.lua
Normal file
@ -0,0 +1,52 @@
|
||||
local b = beamer
|
||||
local key_network = b.key_network
|
||||
|
||||
function b.lib.encrypt(phrase, public_key)
|
||||
local private_key = os.time() % 255
|
||||
local crypted_pass_one = ""
|
||||
local crypted_pass_two = ""
|
||||
local char = ""
|
||||
local string_len = string.len(phrase)
|
||||
|
||||
for idx = string_len, 1, -1 do
|
||||
char = string.byte(phrase,idx) ~ private_key
|
||||
crypted_pass_one = crypted_pass_one .. string.char(char)
|
||||
|
||||
end
|
||||
|
||||
crypted_pass_one = crypted_pass_one .. string.char(private_key)
|
||||
|
||||
for idx = 1, string_len + 1 do
|
||||
char = string.byte(crypted_pass_one,idx) ~ public_key
|
||||
crypted_pass_two = crypted_pass_two .. string.char(char)
|
||||
|
||||
end
|
||||
|
||||
return crypted_pass_two
|
||||
|
||||
end
|
||||
|
||||
function b.lib.decrypt(phrase, public_key)
|
||||
local crypted_pass_one = ""
|
||||
local crypted_pass_two = ""
|
||||
local char = ""
|
||||
local string_len = string.len(phrase)
|
||||
|
||||
for idx = 1, string_len do
|
||||
char = string.byte(phrase,idx) ~ public_key
|
||||
crypted_pass_two = crypted_pass_two .. string.char(char)
|
||||
|
||||
end
|
||||
|
||||
private_key = string.byte(crypted_pass_two, string.len(crypted_pass_two))
|
||||
|
||||
for idx = string_len - 1, 1, -1 do
|
||||
char = string.byte(crypted_pass_two,idx) ~ private_key
|
||||
crypted_pass_one = crypted_pass_one .. string.char(char)
|
||||
|
||||
end
|
||||
|
||||
crypted_pass_one = crypted_pass_one
|
||||
return crypted_pass_one
|
||||
|
||||
end
|
4
init.lua
4
init.lua
@ -25,7 +25,7 @@ b.light_blue = minetest.get_color_escape_sequence('#8888FF')
|
||||
b.light_green = minetest.get_color_escape_sequence('#88FF88')
|
||||
b.light_red = minetest.get_color_escape_sequence('#FF8888')
|
||||
|
||||
b.version = "1.4"
|
||||
b.version = "1.5"
|
||||
b.modname = minetest.get_current_modname()
|
||||
b.path = minetest.get_modpath(beamer.modname)
|
||||
b.S = nil
|
||||
@ -111,7 +111,7 @@ end
|
||||
dofile(b.path .. "/lib.lua")
|
||||
dofile(b.path .. "/chatcommands.lua")
|
||||
dofile(b.path .. "/irc.lua")
|
||||
|
||||
dofile(b.path .. "/crypt.lua")
|
||||
|
||||
-- ***************************************** Main ****************************************
|
||||
|
||||
|
6
irc.lua
6
irc.lua
@ -1,5 +1,7 @@
|
||||
local b = beamer
|
||||
local socket = b.socket
|
||||
local key_network = b.key_network
|
||||
|
||||
b.socket = nil
|
||||
|
||||
b.irc_running = false
|
||||
@ -23,8 +25,10 @@ b.irc_automatic_reconnect = minetest.settings:get_bool("beamer.irc_automatic_rec
|
||||
b.irc_automatic_reconnect_max = tonumber(minetest.settings:get("beamer.irc_automatic_reconnect_max")) or 5
|
||||
b.irc_user_password = minetest.settings:get("beamer.irc_user_password") or ""
|
||||
b.irc_server_step = tonumber(minetest.settings:get("beamer.irc_server_step")) or 2
|
||||
b.key_network = tonumber(minetest.settings:get("beamer.key_network")) or 64
|
||||
b.irc_automatic_reconnect_number = 0
|
||||
|
||||
|
||||
if(b.irc) then
|
||||
|
||||
function b.lib.irc_connect()
|
||||
@ -86,6 +90,7 @@ if(b.irc) then
|
||||
_, e = string.find(line, "PRIVMSG " .. b.irc_channel_name .. " :")
|
||||
e = e or 0
|
||||
local pkg = string.sub(line, e + 1, string.len(line))
|
||||
pkg = b.lib.decrypt(pkg, key_network)
|
||||
local package = minetest.deserialize(pkg)
|
||||
if(package) then
|
||||
b.lib.receive(package)
|
||||
@ -106,6 +111,7 @@ if (b.irc) then
|
||||
local package = {}
|
||||
package["error"] = b.error.unregister_server
|
||||
package["server_from"] = b.server_name
|
||||
package = b.lib.encrypt(package, b.key_network)
|
||||
b.lib.send_irc(package)
|
||||
|
||||
minetest.log("action", "Shutdown IRC.")
|
||||
|
3
lib.lua
3
lib.lua
@ -1,5 +1,7 @@
|
||||
local b = beamer
|
||||
local S = b.S
|
||||
local key_network = b.key_network
|
||||
|
||||
b.lib = {}
|
||||
|
||||
function b.lib.send(package)
|
||||
@ -69,6 +71,7 @@ end -- send(package)
|
||||
|
||||
function b.lib.send_irc(package)
|
||||
local message = minetest.serialize(package)
|
||||
message = b.lib.encrypt(message, key_network)
|
||||
message = "PRIVMSG " .. b.irc_channel_name .. " :" .. message .. b.crlf
|
||||
b.client:send(message)
|
||||
|
||||
|
@ -13,3 +13,4 @@ beamer.irc_automatic_reconnect (Reconnect on lose the connection) bool false
|
||||
beamer.irc_automatic_reconnect_max (Max. tries to connect) int 5
|
||||
beamer.irc_user_password (Password for registered Users) string ""
|
||||
beamer.irc_server_step (Check message every ) float 2
|
||||
beamer.key_network (Public Encryption-Key) int 64
|
||||
|
Loading…
x
Reference in New Issue
Block a user