--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.
got nil
#1
Posted 16 January 2013 - 02:16 AM
#2
Posted 16 January 2013 - 03:15 AM
themegaexcelcorporationbymicroshitooohisaidexcelimeanudbbyurielsalisxDshould 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 by TheOriginalBIT, 16 January 2013 - 03:20 AM.
#3
Posted 16 January 2013 - 03:53 AM
#4
Posted 16 January 2013 - 03:58 AM
b = shell.resolveProgram(a)what is line 128 for you?
#6
Posted 16 January 2013 - 04:40 AM
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...
#7
Posted 16 January 2013 - 04:51 AM
TheOriginalBIT, on 16 January 2013 - 04:40 AM, said:
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...
#8
Posted 16 January 2013 - 04:53 AM
urielsalis, on 16 January 2013 - 04:51 AM, said:
TheOriginalBIT, on 16 January 2013 - 04:40 AM, said:
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...
#9
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 52
#10
Posted 16 January 2013 - 05:35 AM
#11
Posted 16 January 2013 - 05:58 AM
ChunLing, on 16 January 2013 - 05:35 AM, said:
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
#12
Posted 16 January 2013 - 06:03 AM
endlocal function encrypt(text,pass)This causes encode() to still have undefined behavior when you call it.
#13
Posted 16 January 2013 - 06:11 AM
#14
Posted 16 January 2013 - 07:09 AM
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
3 user(s) are reading this topic
0 members, 3 guests, 0 anonymous users











