--dbapi
local function reset()
pass = nil
object = nil
output = nil
end
function decodedbtofileswithallnames(file)
file = fs.open("file", "r")
a = file.readLine()
repeat
c = decrypt(a, "thepasswordshoulnotbeenknow")
b = textutils.unserialize(c)
o = fs.open(a[1], "w")
o.write(a[2])
a = file.readLine
o.close()
until a==nil
end
local function encode(text)
output=""
repeat
output=output..string.byte(text).." "
text=string.sub(text,2)
until string.len(text)==0
end
local function encrypt(text,pass)
text = text.."\n"..pass
encode(pass)
pass=output
temppass=output
encode(text)
text=output
output=""
repeat
a = string.find(temppass..""," ")
b = string.sub(temppass,1,a-1)
c = string.find(text..""," ")
d = string.sub(text,1,c-1)
output=output..b*d.." "
temppass=string.sub(temppass,a+1)
text = string.sub(text,c+1)
if string.find(temppass," ")==nil then
temppass=pass
end
until string.find(text," ")==nil
end
local function decrypt(text, rawpass)
encode(rawpass)
pass=output
temppass=output
output=""
repeat
a = string.find(text..""," ")
b = string.sub(text,1,a-1)
c = string.find(temppass..""," ")
d = string.sub(temppass,1,c-1)
test = pcall(string.char,b/d)
if test==false then
print("Password incorrect could not decrypt!!!")
output=nil
return
end
output = output.. string.char(b/d)
text=string.sub(text,a+1)
temppass=string.sub(temppass,c+1)
if string.match(temppass," ")==nil then
temppass=pass
end
until string.find(text," ")==nil
if string.match(output,rawpass)==nil then
print("Password incorrect could not decrypt!!!")
output=nil
return
end
output=string.gsub(output,"\n"..rawpass,"")
end
local function fencrypt(object,pass)
file=io.open(object,"r")
if file==nil then
print(object.." does not exists")
reset()
end
text=""
repeat
a = file:read()
if a~=nil then
text=text..a.."\n"
end
until a==nil
file:close()
encrypt(text,pass)
return output
end
local function fdecrypt(object,pass,save)
file=io.open(object,"r")
text=""
repeat
a=file:read()
if a~=nil then
text=text..a.."\n"
end
until a==nil
file:close()
decrypt(text,pass)
if output==nil then return end
if save==true then
file=io.open(object,"w")
file:write(output)
file:close()
else
return output
end
end
function setVal(key, value)
data[key] = value
end
function getVal(key)
return data[key]
end
function gettable()
return data
end
function getData()
return object, data.autor
end
function setData(bautor)
n, a = getData()
if not a then
data["autor"] = bautor
return true
else
s = shell.getRunningProgram()
a = shell.getRunningProgram()
b = shell.resolveProgram(a)
print(b..": Error, db "..object.." has alredy an autor, "..data.autor)
return false
end
end
function loadExcel(object)
a = fdecrypt(object,themegaexcelcorporationbymicroshitooohisaidexcelimeanudbbyurielsalisxD,false)
reset()
data = textutils.unserialize(a)
end
function save(name)
s = textutils.serialize(data)
a = fencrypt(s,themegaexcelcorporationbymicroshitooohisaidexcelimeanudbbyurielsalisxD)
reset()
file = fs.open(name, "w")
file.write(a)
file.close()
end
function closeExcel()
data = nil
end
When i try to create the table data to simulate a loaded db and i tried to write a val it got nil the same when i tried to load an db, i ccreated a script that load the api and then try to do that but is not working.
This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
got nil
Started by FuuuAInfiniteLoop(F.A.I.L), 16 January 2013 - 01:16 AMPosted 16 January 2013 - 02:16 AM
Posted 16 January 2013 - 03:15 AM
this
this
can be replaced with
this reads all preserving new lines.
other than that, please expand on "its not working" … what exactly is not working? does it error, or is it just not performing as expected?
themegaexcelcorporationbymicroshitooohisaidexcelimeanudbbyurielsalisxD
should be in quotes as there is nowhere its declared as a variable.this
repeat
a=file:read()
if a~=nil then
text=text..a.."\n"
end
until a==nil
can be replaced with
text = file:read("*a")
this reads all preserving new lines.
other than that, please expand on "its not working" … what exactly is not working? does it error, or is it just not performing as expected?
Edited on 16 January 2013 - 02:20 AM
Posted 16 January 2013 - 03:53 AM
when i trie with your correctio it said: test:128 attempt to index ?, a nil value HELP
Posted 16 January 2013 - 03:58 AM
according to the line numbers in my ide line 128 is this
b = shell.resolveProgram(a)
what is line 128 for you?Posted 16 January 2013 - 04:38 AM
return object, data.autoraccording to the line numbers in my ide line 128 is thiswhat is line 128 for you?b = shell.resolveProgram(a)
is in the function getData()
Posted 16 January 2013 - 04:40 AM
Typo maybe? Shouldn't it be author not autor?
Edit: wait I do see you initialize it as that… But do you ever tell the program that data is a table? Can't see it in the code on my phone…
Edit: wait I do see you initialize it as that… But do you ever tell the program that data is a table? Can't see it in the code on my phone…
Posted 16 January 2013 - 04:51 AM
iim spanish so i put autor (typo) but all references are like thatTypo maybe? Shouldn't it be author not autor?
Edit: wait I do see you initialize it as that… But do you ever tell the program that data is a table? Can't see it in the code on my phone…
Posted 16 January 2013 - 04:53 AM
Yeh I realized that after I said it. Put data = { } at the top… Should fix it…iim spanish so i put autor (typo) but all references are like thatTypo maybe? Shouldn't it be author not autor?
Edit: wait I do see you initialize it as that… But do you ever tell the program that data is a table? Can't see it in the code on my phone…
Posted 16 January 2013 - 05:11 AM
--dbapi
data = {}
local function reset()
pass = nil
object = nil
output = nil
end
function decodedbtofileswithallnames(file)
file = fs.open("file", "r")
a = file.readLine()
repeat
c = decrypt(a, "thepasswordshoulnotbeenknow")
b = textutils.unserialize(c)
o = fs.open(a[1], "w")
o.write(a[2])
a = file.readLine
o.close()
until a==nil
end
local function encode(text)
output=""
repeat
output=output..string.byte(text).." "
text=string.sub(text,2)
until string.len(text)==0
endlocal function encrypt(text,pass)
text = text.."\n"..pass
encode(pass)
pass=output
temppass=output
encode(text)
text=output
output=""
repeat
a = string.find(temppass..""," ")
b = string.sub(temppass,1,a-1)
c = string.find(text..""," ")
d = string.sub(text,1,c-1)
output=output..b*d.." "
temppass=string.sub(temppass,a+1)
text = string.sub(text,c+1)
if string.find(temppass," ")==nil then
temppass=pass
end
until string.find(text," ")==nil
end
local function decrypt(text, rawpass)
output = encode(rawpass)
pass=output
temppass=output
output=""
repeat
a = string.find(text..""," ")
b = string.sub(text,1,a-1)
c = string.find(temppass..""," ")
d = string.sub(temppass,1,c-1)
test = pcall(string.char,b/d)
if test==false then
print("Password incorrect could not decrypt!!!")
output=nil
return
end
output = output.. string.char(b/d)
text=string.sub(text,a+1)
temppass=string.sub(temppass,c+1)
if string.match(temppass," ")==nil then
temppass=pass
end
until string.find(text," ")==nil
if string.match(output,rawpass)==nil then
print("Password incorrect could not decrypt!!!")
output=nil
return
end
output=string.gsub(output,"\n"..rawpass,"")
endlocal function fencrypt(object,pass)
file=io.open(object,"r")
if file==nil then
print(object.." does not exists")
reset()
end
text=""
repeat
a = file:read()
if a~=nil then
text=text..a.."\n"
end
until a==nil
file:close()
encrypt(text,pass)
return output
end
local function fdecrypt(object,pass,save)
file=io.open(object,"r")
text=""
repeat
a=file:read()
if a~=nil then
text=text..a.."\n"
end
until a==nil
file:close()
decrypt(text,pass)
if output==nil then return end
if save==true then
file=io.open(object,"w")
file:write(output)
file:close()
else
return output
end
end
function setVal(key, value)
data[key] = value
end
function getVal(key)
return data[key]
end
function gettable()
return data
end
function getData()
return object, data["autor"]
end
function setData(bautor)
n, a = getData()
if not a then
data["autor"] = bautor
return true
else
s = shell.getRunningProgram()
a = shell.getRunningProgram()
b = shell.resolveProgram(a)
print(b..": Error, db "..object.." has alredy an autor, "..data.autor)
return false
end
end
function loadExcel(object)
a = fdecrypt(object,"themegaexcelcorporationbymicroshitooohisaidexcelimeanudbbyurielsalisxD",false)
reset()
data = textutils.unserialize(a)
end
function save(name)
s = textutils.serialize(data)
a = fencrypt(s,"themegaexcelcorporationbymicroshitooohisaidexcelimeanudbbyurielsalisxD")
reset()
file = fs.open(name, "w")
file.write(a)
file.close()
end
function closeExcel()
data = nil
end
now nil is on line 52Posted 16 January 2013 - 05:35 AM
Where is the encode() function supposed to end, and what is it supposed to return?
Posted 16 January 2013 - 05:58 AM
Where is the encode() function supposed to end, and what is it supposed to return?
local function encode(text)
output=""
repeat
output=output..string.byte(text).." "
text=string.sub(text,2)
until string.len(text)==0
endlocal function encrypt(text,pass)
text = text.."\n"..pass
encode(pass)
pass=output
temppass=output
encode(text)
text=output
output=""
repeat
a = string.find(temppass..""," ")
b = string.sub(temppass,1,a-1)
c = string.find(text..""," ")
d = string.sub(text,1,c-1)
output=output..b*d.." "
temppass=string.sub(temppass,a+1)
text = string.sub(text,c+1)
if string.find(temppass," ")==nil then
temppass=pass
end
until string.find(text," ")==nil
end
Posted 16 January 2013 - 06:03 AM
You've managed to obscure one of your "end"s by concatenating it with a local.
endlocal function encrypt(text,pass)
This causes encode() to still have undefined behavior when you call it.Posted 16 January 2013 - 06:11 AM
can you correct my code because i dont have understood anything that you said
Posted 16 January 2013 - 07:09 AM
Here, read the comments..
local function encode(text)
output=""
repeat
output=output..string.byte(text).." "
text=string.sub(text,2)
until string.len(text)==0
--[[ Your problem was here, you had
'endlocal' as one word, instead
of two
endlocal function encrypt(text,pass)]]
end
local function encrypt(text,pass)
text = text.."\n"..pass
encode(pass)
pass=output
temppass=output
encode(text)
text=output
output=""
repeat
a = string.find(temppass..""," ")
b = string.sub(temppass,1,a-1)
c = string.find(text..""," ")
d = string.sub(text,1,c-1)
output=output..b*d.." "
temppass=string.sub(temppass,a+1)
text = string.sub(text,c+1)
if string.find(temppass," ")==nil then
temppass=pass
end
until string.find(text," ")==nil
end