Jump to content




got nil


  • You cannot reply to this topic
13 replies to this topic

#1 FuuuAInfiniteLoop(F.A.I.L)

  • Banned
  • 435 posts
  • LocationThe left part of this post

Posted 16 January 2013 - 02:16 AM

--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.

#2 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 16 January 2013 - 03:15 AM

this
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 by TheOriginalBIT, 16 January 2013 - 03:20 AM.


#3 FuuuAInfiniteLoop(F.A.I.L)

  • Banned
  • 435 posts
  • LocationThe left part of this post

Posted 16 January 2013 - 03:53 AM

when i trie with your correctio it said: test:128 attempt to index ?, a nil value HELP

#4 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

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?

#5 FuuuAInfiniteLoop(F.A.I.L)

  • Banned
  • 435 posts
  • LocationThe left part of this post

Posted 16 January 2013 - 04:38 AM

View PostTheOriginalBIT, on 16 January 2013 - 03:58 AM, said:

according to the line numbers in my ide line 128 is this
b = shell.resolveProgram(a)
what is line 128 for you?
return object, data.autor

is in the function getData()

#6 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

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...

#7 FuuuAInfiniteLoop(F.A.I.L)

  • Banned
  • 435 posts
  • LocationThe left part of this post

Posted 16 January 2013 - 04:51 AM

View PostTheOriginalBIT, on 16 January 2013 - 04:40 AM, said:

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...
iim spanish so i put autor (typo) but all references are like that

#8 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 16 January 2013 - 04:53 AM

View Posturielsalis, on 16 January 2013 - 04:51 AM, said:

View PostTheOriginalBIT, on 16 January 2013 - 04:40 AM, said:

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...
iim spanish so i put autor (typo) but all references are like that
Yeh I realized that after I said it. Put data = { } at the top... Should fix it...

#9 FuuuAInfiniteLoop(F.A.I.L)

  • Banned
  • 435 posts
  • LocationThe left part of this post

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 ChunLing

  • Members
  • 2,027 posts

Posted 16 January 2013 - 05:35 AM

Where is the encode() function supposed to end, and what is it supposed to return?

#11 FuuuAInfiniteLoop(F.A.I.L)

  • Banned
  • 435 posts
  • LocationThe left part of this post

Posted 16 January 2013 - 05:58 AM

View PostChunLing, on 16 January 2013 - 05:35 AM, said:

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


#12 ChunLing

  • Members
  • 2,027 posts

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.

#13 FuuuAInfiniteLoop(F.A.I.L)

  • Banned
  • 435 posts
  • LocationThe left part of this post

Posted 16 January 2013 - 06:11 AM

can you correct my code because i dont have understood anything that you said

#14 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

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






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users