This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
crazyadam0's profile picture

(As Usual) Attempt to call nil on file.writeline()

Started by crazyadam0, 22 February 2014 - 04:30 AM
crazyadam0 #1
Posted 22 February 2014 - 05:30 AM
I have been coding again on my attempt at an os and I added password encryption. At least, I attempted to. For some reason that I can't explain when running this there is an "Attempt to call nil" on line 104 of my os prerequisites checker: file.writeLine(sha.sha256(pwd)); Does anyone know why this is and or how to fix it?

Source Code:

http://pastebin.com/kYPevJqU
NOTE: I will add a salt once this works dont even bring it up.
NOTE2: For the program to accept the password it must be at least 7 characters long.
Bomb Bloke #2
Posted 22 February 2014 - 05:38 AM
Well, the file write a couple of lines up worked, implying "file.writeLine" isn't nil and thus "sha.sha256" is. Where's the source for "sha"? Is there a global function in there called "sha256"?
crazyadam0 #3
Posted 22 February 2014 - 05:45 AM
No, if you look around in places like line 103 where it is loaded you will wind it at /.winMC/.OS/APIs/sha.
CometWolf #4
Posted 22 February 2014 - 06:39 AM

local function sha256(msg)
	    msg = preproc(msg, #msg)
	    local H = initH256({})
	    for i = 1, #msg, 64 do digestblock(msg, i, H) end
	    return str2hexa(num2s(H[1], 4) .. num2s(H[2], 4) .. num2s(H[3], 4) .. num2s(H[4], 4) ..
			    num2s(H[5], 4) .. num2s(H[6], 4) .. num2s(H[7], 4) .. num2s(H[8], 4))
end
It's defined as a local function in the "api" so you don't have acess to it when using os.loadAPI.
Bomb Bloke #5
Posted 22 February 2014 - 07:00 AM
Ah, I see, your script grabs the SHA stuff via PasteBin. Yeah, GravityScore's SHA script isn't an API; he intends that you paste the whole thing into your own code.
crazyadam0 #6
Posted 22 February 2014 - 01:33 PM

local function sha256(msg)
		msg = preproc(msg, #msg)
		local H = initH256({})
		for i = 1, #msg, 64 do digestblock(msg, i, H) end
		return str2hexa(num2s(H[1], 4) .. num2s(H[2], 4) .. num2s(H[3], 4) .. num2s(H[4], 4) ..
				num2s(H[5], 4) .. num2s(H[6], 4) .. num2s(H[7], 4) .. num2s(H[8], 4))
end
It's defined as a local function in the "api" so you don't have acess to it when using os.loadAPI.
Thank you I see now, that makes a lot of sense.

Ah, I see, your script grabs the SHA stuff via PasteBin. Yeah, GravityScore's SHA script isn't an API; he intends that you paste the whole thing into your own code.
Okay, I didnt know he intended it to be pasted in and not used as an API, but I can do that.

Thank you both for the help!