Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- By tom2018 5/10/2013 last updated 5/11/2013
- -- feel free to modify any part of this program
- -- just please send me a PM on the forums!
- --encryption found when searching around, author unknown msg me on forums if you own this code and would
- --like me to remove it or give you credits
- function enc(str, key) -- Function
- local tProp = {} -- Make table
- for i = 1, str:len() do -- loop for str length
- local val = tonumber((str:byte(i) * tonumber(key) + (12.6 * key)) / 2.8)--Byte str times keyadd 12.6 times key and divide 2.8
- table.insert(tProp, val) -- rest is to return the data
- end
- return tostring(table.concat(tProp,"|"))
- end
- function dec(str, key)
- local data = {}
- for word in string.gmatch(str, "[^|]+") do
- local rdata = ((tonumber(word)*2.8)-(12.6*key))/key
- table.insert(data, math.floor(rdata+0.5))
- end
- return string.char(unpack(data))
- end
- --config
- side = "top" --modem
- rand = false --more secure not yet implemented
- btlp = false --not yet implement
- stpmsg = "end" --msg that indicates end of file
- shtdown = false -- if true will shutdown at end of file transfer
- gfb = true -- return current file size and other usefull data
- pmsg = "ping" --default ping msg
- dc = false --basic encryption method (eta will be wrong)
- vsn = 1.4 -- version
- cp = true -- keep pinging if failed connection
- --code
- rednet.open(side)
- term.clear()
- term.setCursorPos(1,1)
- print("tomsfiletranfer "..vsn.." |")
- print("by tom2018 |")
- print("---------------------#")
- print('Type help for command list')
- while true do
- ct = false
- write("action> ")
- p = read()
- if p == "help" then
- print[[help -cmd list
- exit -leave program
- id -computer id
- files -send file
- filer -receive file]]
- ct = true
- end
- if p == "id" then
- print(os.getComputerID())
- ct = true
- end
- if p == "filer" then
- write("ID> ")
- cid = read()
- stop = false
- cid = cid + 0
- write("save as: ")
- nami = read()
- h = fs.open(nami,"w")
- write("ping msg> ")
- rednet.send(cid,read())
- while stop == false do
- icid, pack = rednet.receive(2)
- if cp == false then
- if icid == nil then
- print("no connection established!")
- sleep(1.5)
- os.reboot()
- end
- else
- if icid == nil then
- print("no connection established.")
- sleep(1.5)
- end
- end
- if icid == cid then
- print("Received "..pack.." Saving to file")
- if pack ~= stpmsg then
- h.write(pack)
- if gfb == true then
- print(fs.getSize(nami))
- end
- else
- print("file complete!")
- if dc == true then
- write("key> ")
- keys = read()
- h.close()
- h = fs.open(nami,'r')
- nonen = h.readAll()
- h.close()
- h = fs.open(nami,'w')
- h.write(dec(nonen,keys))
- end
- if dc == false then
- h.close()
- end
- stop = true
- if shtdown == true then
- os.shutdown()
- else
- os.reboot()
- end
- end
- elseif icid ~= nil then
- print("Blocked Conection from ID: "..icid)
- end
- sleep(0)
- end
- ct = true
- end
- if p == "files" then
- write("file> ")
- nami = read()
- if dc == true then
- write("key> ")
- keys = read()
- end
- h = fs.open(nami,"r")
- if dc == false then
- wpack = h.readAll()
- else
- wpack = enc(h.readAll(), keys)
- end
- wpackt = {}
- print("Dividing into Packets may take a while!")
- for char in string.gmatch(wpack, ".") do
- table.insert(wpackt, char)
- sleep(0)
- end
- if gfb == true then
- print("hosting on "..os.getComputerID())
- eta = #wpackt * .01
- print("Estimated transfer time in seconds")
- print(eta)
- end
- while true do
- cid, auth = rednet.receive()
- stop = false
- c = 1
- wpn = #wpackt + 1
- if auth == "sup" then
- print("Seeding ID:"..cid)
- while c < wpn do
- rednet.send(cid, wpackt[c])
- c = c + 1
- sleep(0.01)
- end
- rednet.send(cid, stpmsg)
- print("Seed Complete!")
- elseif auth == pmsg then
- rednet.send(cid,nami)
- end
- sleep(0)
- end
- ct = true
- end
- if p == "exit" then
- print("Thankyou for using Tomsfiletransfer.")
- sleep(1.5)
- os.reboot()
- ct = true
- end
- if ct == false then
- print("Cmd not recongnized.")
- end
- sleep(0)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement