Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local BANK_CHANNEL = 1329
- local function convert(chars,dist,inv)
- local charInt = string.byte(chars);
- for i=1,dist do
- if(inv)then charInt = charInt - 1; else charInt = charInt + 1; end
- if(charInt<32)then
- if(inv)then charInt = 126; else charInt = 126; end
- elseif(charInt>126)then
- if(inv)then charInt = 32; else charInt = 32; end
- end
- end
- return string.char(charInt);
- end
- local function crypt(str,k,inv)
- local enc= "";
- for i=1,#str do
- if(#str-k[5] >= i or not inv)then
- for inc=0,3 do
- if(i%4 == inc)then
- enc = enc .. convert(string.sub(str,i,i),k[inc+1],inv);
- break;
- end
- end
- end
- end
- if(not inv)then
- for i=1,k[5] do
- enc = enc .. string.char(math.random(32,126));
- end
- end
- return enc;
- end
- local modem
- local function getModem()
- for i,v in pairs(peripheral.getNames()) do
- if peripheral.getType(v) == "modem" then
- modem = peripheral.wrap(v)
- modem.open(BANK_CHANNEL)
- break
- end
- end
- end
- local myKey
- local function sendMessage(text)
- text = textutils.serialize(text)
- print(text)
- modem.transmit(BANK_CHANNEL, os.getComputerID(), crypt(text, myKey))
- end
- local function receiveMessage()
- local event, side, from, id, text
- repeat
- event, side, from, id, text = os.pullEvent("modem_message")
- text = textutils.unserialize(crypt(text, myKey, true))
- until from == BANK_CHANNEL and id == BANK_CHANNEL and type(text) == "table" and text[1] == os.getComputerID()
- return text[2]
- end
- function createUser(user, pass)
- sendMessage({"createUser", user, pass})
- local tab = receiveMessage()
- if tab[1] == false then
- return false, tab[2]
- else
- return true
- end
- end
- local function loadKey()
- if fs.exists(".bankkey") then
- local file = fs.open(".bankkey", "r")
- myKey = textutils.unserialize(file.readAll())
- file.close()
- else
- modem.transmit(BANK_CHANNEL, os.getComputerID(), "@!)#njsdf)(#84njd)")
- local event, side, from, id, text
- repeat
- event, side, from, id, text = os.pullEvent("modem_message")
- until from == BANK_CHANNEL and id == BANK_CHANNEL
- myKey = textutils.unserialize(text)
- local file = fs.open(".bankkey", "w")
- file.write(textutils.serialize(myKey))
- file.close()
- end
- end
- function load()
- getModem()
- if not modem then
- error("No modem attached", 0)
- end
- loadKey()
- end
Add Comment
Please, Sign In to add comment