Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local args = {...}
- local m = peripheral.find("modem") -- Yay for CC1.6
- local hist = {}
- local histc = 0
- local flines = {}
- local nick = "Luca"
- local x, y = term.getSize()
- local line = 1
- local msg = ""
- local aes = dofile("/libs/cryptLib").aes()
- local utils = dofile("/libs/cryptLib").utils()
- local f = fs.open(args[1],"r")
- for fline in f.readLine do
- flines[#flines+1] = fline
- end
- f.close()
- f = fs.open(args[2], "r")
- local key = textutils.unserialize(f.readLine())
- f.close()
- local function encrypt(plain)
- plain = utils.stringToByteArray(plain)
- local iv = utils.keygen(16)
- local c_text = aes.encrypt_cbc(plain, key, iv)
- return {c_text, iv}
- end
- local function decrypt(c_text, iv)
- local plain = aes.decrypt_cbc(c_text, key, iv)
- return utils.byteArrayToString(plain)
- end
- term.clear()
- term.setCursorPos(1,1)
- print("Welcome to Chat!")
- print("IDs im Chatraum:")
- for i = 1,#flines do
- print(flines[i])
- m.open(tonumber(flines[i]))
- end
- sleep(3)
- term.clear()
- while true do
- term.setCursorPos(1, y)
- term.setBackgroundColor(colors.gray)
- term.clearLine()
- write("Message:"..msg)
- term.setBackgroundColor(32768)
- local e = {os.pullEvent()}
- if e[1] == "char" then
- msg = msg..e[2]
- elseif e[1] == "modem_message" then
- local c_text, iv = aes.validate(e[5])
- if c_text then
- if line == y -1 then
- term.clear()
- line = 1
- end
- rs.setOutput("left",true)
- sleep(0.1)
- rs.setOutput("left",false)
- term.setCursorPos(1, line)
- local plain = decrypt(c_text, iv)
- print(plain)
- line = line + 1
- end
- elseif e[1] == "key" then
- if e[2] == 14 then
- term.setCursorPos(1,1)
- msg = msg:sub(0,#msg-1)
- elseif e[2] == 28 then
- hist[#hist + 1] = msg
- msg = "<"..nick..">"..msg
- if line == y -1 then
- term.clear()
- line = 1
- end
- term.setCursorPos(1, line)
- print(msg)
- line = line + 1
- msg = encrypt(msg)
- m.transmit(os.getComputerID(),os.getComputerID(),msg)
- msg = ""
- elseif e[2] == 200 then
- histc = histc + 1
- if histc > #hist then
- histc = histc - 1
- else
- msg = hist[#hist-histc+1]
- end
- elseif e[2] == 208 then
- histc = histc - 1
- if histc == 0 then
- msg = ""
- elseif histc < 0 then
- histc = histc + 1
- else
- msg = hist[#hist-histc+1]
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement