Whisk: This Programm works not on SimSoft, because ther is no option to add variables such as idfilter, path,..
I've revised it slightly:
Spoiler
--[[
Whisk - File/Folder Transmitter for ComputerCraft
by EldidiStroyrr
TODO:
-do encryption
-polish up a bit
get with
pastebin get 4ZRHE4Ar whisk
std pb 4ZRHE4Ar whisk
std ld whisk whisk
--]]
term.clear()
term.setCursorPos(1,1)
term.setTextColor(1)
print("send/receive: ")
sere = read()
print("path: ")
path = read()
print("idfilter: ")
idf = read()
print("password: ")
pass = read()
local channel = 2845
local modem = peripheral.find("modem")
if not modem then
error("No modem detected.")
end
modem.open(channel)
local displayHelp = function()
local helptxt = [[
Whisk - file/folder sender
whisk send <path> [idfilter] [password]
whisk receive [path] [idfilter] [password]
]]
write(helptxt)
end
--API made by valithor.
local encrypt = function(msg,key)
local num = ""
for i = 1, #key do
local let = key:sub(i,i):byte()
num = let <= 9 and num.."99"..let or let<=99 and num.."9"..let or num..let
num = #msg..num
end
math.randomseed(tonumber(num))
local encrypt = ""
for i = 1, #msg do
local rotation = math.random(0,94)
local byte = msg:sub(i,i):byte()
local rotate = rotation+byte <= 127 and rotation +byte or ((rotation+byte)%127)+32
encrypt = encrypt..string.char(rotate)
end
return encrypt
end
local decrypt = function(msg,key)
local num = ""
for i = 1, #key do
local let = key:sub(i,i):byte()
num = let <= 9 and num.."99"..let or let<=99 and num.."9"..let or num..let
num = #msg..num
end
math.randomseed(tonumber(num))
local decrypt = ""
for i = 1, #msg do
local rotation = math.random(0,94)
local byte = msg:sub(i,i):byte()
local rotate = byte-rotation >= 32 and byte-rotation or byte-rotation
if rotate < 32 then
rotate = rotate+95
end
decrypt = decrypt..string.char(rotate)
end
return decrypt
end
local tEnc = function(msg,key)
return encrypt(encrypt(tostring(msg),key),tostring(math.floor(os.time()/2)))
end
local tDec = function(msg,key)
return decrypt(decrypt(tostring(msg),key),tostring(math.floor(os.time()/2)))
end
listAll = function(_path, _files, noredundant) --Thanks Lyqyd!
local path = _path or ""
local files = _files or {}
if #path > 1 then table.insert(files, path) end
for _, file in ipairs(fs.list(path)) do
local path = fs.combine(path, file)
if fs.isDir(path) then
listAll(path, files)
else
table.insert(files, path)
end
end
if noredundant then
for a = 1, #files do
if fs.isDir(tostring(files[a])) then
if #fs.list(tostring(files[a])) ~= 0 then
table.remove(files,a)
end
end
end
end
return files
end
local function choice(input)
repeat
local event, button = os.pullEvent("key")
if type(button) == "number" then button = keys.getName(button) end
if button == nil then button = " " end
until string.find(input, button)
return button
end
local defaultKey = "swordfish" --the most secure.
local tArg = {sere, path, idf, pass}
local mode, itPath, idfilter, enckey = tArg[1], tArg[2], tonumber(tArg[3]), tArg[4]
filetree = {}
if not enckey then enckey = defaultKey end --boo hoo, y u no have a password?
output = {}
if mode == "send" then
if not fs.exists(itPath) then
error("No such file.")
end
contents = {}
if not fs.isDir(itPath) then
local file = fs.open(itPath,"r")
line = ""
while line do
line = file.readLine()
table.insert(contents,line)
end
filetree = {[fs.getName(itPath)] = {fyle = contents, dir = false}}
file.close()
output = {id = os.getComputerID(), files = filetree}
else
filelist = listAll(itPath,nil,true)
for a = 1, #filelist do
local isDir
contents = {}
if not fs.isDir(filelist[a]) then
local file = fs.open(filelist[a],"r")
local line = ""
while line do
line = file.readLine()
table.insert(contents,line)
end
file.close()
isDir = false
else
contents = {""}
isDir = true
end
if fs.combine("",shell.resolve(itPath)) == "" then --This oughta fix things
filelist[a] = fs.combine("root"..os.getComputerID(),filelist[a])
end
filetree[filelist[a]] = {fyle = contents, dir = isDir}
end
output = {id = os.getComputerID(), files = filetree}
end
modem.transmit(channel,channel,output)
elseif mode == "receive" then
local combinedSize = 0
local filecount = 0
--local event, side, sendID, repChannel, msg
write("Receiving")
if idfilter then
write(" from id"..idfilter.."...")
else
write("...")
end
print("(X to cancel)")
while true do
input = {}
event, side, sendChannel, repChannel, msg = os.pullEvent()
if event == "char" and string.lower(side) == "x" then
print("Cancelled.")
return false
end
if type(msg) == "table" then
if type(msg.files) == "table" and (idfilter or msg.id) == msg.id then
break
end
end
end
for k,v in pairs(msg.files) do
local fee
if not itPath then
fee = k
else
local slashpos = string.find(k,"/") or 1
fee = fs.combine(itPath,string.sub(k,slashpos))
end
filecount = filecount + 1
if fs.exists(fee) and fee == k then
print("Overwrite '"..fee.."'? [Y/N]")
if choice("yn") == "y" then
if not itPath then
if not fs.exists(fs.getDir(fee)) then fs.makeDir(fs.getDir(fee)) end
end
if type(v) == "table" then
if v.dir then
fs.makeDir(fee)
else
local file
if not itPath then
file = fs.open(fee,"w")
end
file.write(table.concat(v.fyle,"\n"))
file.close()
combinedSize = combinedSize + fs.getSize(fee)
end
end
end
else
if not fs.exists(fs.getDir(fee)) then fs.makeDir(fs.getDir(fee)) end
if type(v) == "table" then
if v.dir then
fs.makeDir(fee)
else
local file = fs.open(fee,"w")
if file then
file.write(table.concat(v.fyle,"\n"))
file.close()
combinedSize = combinedSize + fs.getSize(fee)
end
end
end
end
end
write("Done (got "..filecount.." file")
if filecount > 1 then write("s")end
print(" from id"..msg.id..")")
else
return displayHelp()
end
sleep(0)
Enchat: In this program, I get only an error
enchat: 200: Expected number